pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: getattr-after-close2-hacks+wintirpc wrappers, 2024-03-04
Posted by Anonymous on Mon 4th Mar 2024 18:43
raw | new post

  1. From 80130d82bac62a58a7a4429ebff48bdb1180d8ac Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 4 Mar 2024 09:47:17 +0100
  4. Subject: [PATCH 1/3] libtirpc: Add wintirpc wrappers for |bind()|+|connect()|
  5.  
  6. Add wintirpc wrappers for |bind()|--->|wintirpc_bind()|
  7. and |connect()|--->|wintirpc_connect()|.
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. libtirpc/src/auth_time.c    |  7 +++++--
  12.  libtirpc/src/bindresvport.c |  4 ++--
  13.  libtirpc/src/clnt_dg.c      |  4 ++--
  14.  libtirpc/src/clnt_vc.c      |  2 +-
  15.  libtirpc/src/rpc_soc.c      |  4 ++--
  16.  libtirpc/src/rpcb_clnt.c    |  2 +-
  17.  libtirpc/src/rtime.c        |  2 +-
  18.  libtirpc/src/svc_generic.c  |  4 ++--
  19.  libtirpc/src/wintirpc.c     | 10 ++++++++++
  20.  libtirpc/tirpc/wintirpc.h   |  2 ++
  21.  10 files changed, 28 insertions(+), 13 deletions(-)
  22.  
  23. diff --git a/libtirpc/src/auth_time.c b/libtirpc/src/auth_time.c
  24. index 2794534..95faae8 100644
  25. --- a/libtirpc/src/auth_time.c
  26. +++ b/libtirpc/src/auth_time.c
  27. @@ -425,7 +425,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid)
  28.                         saw_alarm = 0;
  29.                         /* XXX Need Windows signal/alarm stuff here XXX */
  30.  #endif
  31. -                       res = connect(_get_osfhandle(s), (struct sockaddr *)&sin, sizeof(sin));
  32. +                       res = wintirpc_connect(s, (struct sockaddr *)&sin, sizeof(sin));
  33.                         if (res == SOCKET_ERROR) {
  34.                                 msg("failed to connect to tcp endpoint.");
  35.                                 goto error;
  36. @@ -434,8 +434,11 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid)
  37.                                 msg("alarm caught it, must be unreachable.");
  38.                                 goto error;
  39.                         }
  40. -//                     res = read(_get_osfhandle(s), (char *)&thetime, sizeof(thetime));
  41. +#ifndef _WIN32
  42. +                       res = read(s, (char *)&thetime, sizeof(thetime));
  43. +#else
  44.                         res = (int)wintirpc_recv(s, (char *)&thetime, sizeof(thetime), 0);
  45. +#endif
  46.                         if (res != sizeof(thetime)) {
  47.                                 if (saw_alarm)
  48.                                         msg("timed out TCP call.");
  49. diff --git a/libtirpc/src/bindresvport.c b/libtirpc/src/bindresvport.c
  50. index 874a589..d33deb7 100644
  51. --- a/libtirpc/src/bindresvport.c
  52. +++ b/libtirpc/src/bindresvport.c
  53. @@ -125,7 +125,7 @@ bindresvport_sa(sd, sa)
  54.                  *portp = htons(port++);
  55.                   if (port > endport)
  56.                          port = startport;
  57. -                res = bind(_get_osfhandle(sd), sa, salen);
  58. +                res = wintirpc_bind(sd, sa, salen);
  59.                 if (res >= 0 || errno != EADDRINUSE)
  60.                         break;
  61.          }
  62. @@ -242,7 +242,7 @@ bindresvport_sa(sd, sa)
  63.         }
  64.  #endif
  65.  
  66. -       error = bind(_get_osfhandle(sd), sa, salen);
  67. +       error = wintirpc_bind(sd, sa, salen);
  68.         if (error) {
  69.                 int err = WSAGetLastError();
  70.         }
  71. diff --git a/libtirpc/src/clnt_dg.c b/libtirpc/src/clnt_dg.c
  72. index 9798a8c..7541656 100644
  73. --- a/libtirpc/src/clnt_dg.c
  74. +++ b/libtirpc/src/clnt_dg.c
  75. @@ -366,7 +366,7 @@ clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
  76.         nextsend_time = cu->cu_wait.tv_sec * 1000 + cu->cu_wait.tv_usec / 1000;
  77.  
  78.         if (cu->cu_connect && !cu->cu_connected) {
  79. -               if (connect(_get_osfhandle(cu->cu_fd), (struct sockaddr *)&cu->cu_raddr,
  80. +               if (wintirpc_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
  81.                     cu->cu_rlen) < 0) {
  82.                         cu->cu_error.re_errno = errno;
  83.                         cu->cu_error.re_status = RPC_CANTSEND;
  84. @@ -477,7 +477,7 @@ get_reply:
  85.           msg.msg_flags = 0;
  86.           msg.msg_control = cbuf;
  87.           msg.msg_controllen = 256;
  88. -         ret = recvmsg (_get_osfhandle(cu->cu_fd), &msg, MSG_ERRQUEUE);
  89. +         ret = recvmsg (cu->cu_fd, &msg, MSG_ERRQUEUE);
  90.           if (ret >= 0
  91.               && memcmp (cbuf + 256, cu->cu_outbuf, ret) == 0
  92.               && (msg.msg_flags & MSG_ERRQUEUE)
  93. diff --git a/libtirpc/src/clnt_vc.c b/libtirpc/src/clnt_vc.c
  94. index 3753462..6a4639c 100644
  95. --- a/libtirpc/src/clnt_vc.c
  96. +++ b/libtirpc/src/clnt_vc.c
  97. @@ -413,7 +413,7 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz, cb_xdr, cb_fn, cb_args)
  98.  //                     thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
  99.                         goto err;
  100.                 }
  101. -               if (connect(_get_osfhandle(fd), (struct sockaddr *)raddr->buf, raddr->len) == SOCKET_ERROR){
  102. +               if (wintirpc_connect(fd, (struct sockaddr *)raddr->buf, raddr->len) == SOCKET_ERROR){
  103.                         rpc_createerr.cf_stat = RPC_SYSTEMERROR;
  104.                         rpc_createerr.cf_error.re_errno = WSAGetLastError();
  105.                         mutex_unlock(&clnt_fd_lock);
  106. diff --git a/libtirpc/src/rpc_soc.c b/libtirpc/src/rpc_soc.c
  107. index 3073dac..5e5302a 100644
  108. --- a/libtirpc/src/rpc_soc.c
  109. +++ b/libtirpc/src/rpc_soc.c
  110. @@ -546,7 +546,7 @@ clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz)
  111.         if (*sockp == SOCKET_ERROR) {
  112.                 *sockp = wintirpc_socket(AF_UNIX, SOCK_STREAM, 0);
  113.                 len = SUN_LEN(raddr);
  114. -               if ((*sockp == -1) || (connect(_get_osfhandle(*sockp),
  115. +               if ((*sockp == -1) || (wintirpc_connect(*sockp,
  116.                     (struct sockaddr *)raddr, len) == SOCKET_ERROR)) {
  117.                         rpc_createerr.cf_stat = RPC_SYSTEMERROR;
  118.                         rpc_createerr.cf_error.re_errno = errno;
  119. @@ -604,7 +604,7 @@ svcunix_create(sock, sendsize, recvsize, path)
  120.         addrlen = sizeof(struct sockaddr_un);
  121.         sa = (struct sockaddr *)&sun;
  122.  
  123. -       if (bind(_get_osfhandle(sock), sa, addrlen) == SOCKET_ERROR)
  124. +       if (wintirpc_bind(sock, sa, addrlen) == SOCKET_ERROR)
  125.                 goto done;
  126.  
  127.         taddr.addr.len = taddr.addr.maxlen = addrlen;
  128. diff --git a/libtirpc/src/rpcb_clnt.c b/libtirpc/src/rpcb_clnt.c
  129. index 906db37..5e94d33 100644
  130. --- a/libtirpc/src/rpcb_clnt.c
  131. +++ b/libtirpc/src/rpcb_clnt.c
  132. @@ -682,7 +682,7 @@ __rpcbind_is_up()
  133.         sun.sun_family = AF_UNIX;
  134.         strncpy(sun.sun_path, _PATH_RPCBINDSOCK, sizeof(sun.sun_path));
  135.  
  136. -       if (connect(_get_osfhandle(sock), (struct sockaddr *)&sun, sizeof(sun)) == SOCKET_ERROR) {
  137. +       if (wintirpc_connect(sock, (struct sockaddr *)&sun, sizeof(sun)) == SOCKET_ERROR) {
  138.                 wintirpc_close(sock);
  139.                 return (FALSE);
  140.         }
  141. diff --git a/libtirpc/src/rtime.c b/libtirpc/src/rtime.c
  142. index d6856b6..beaf828 100644
  143. --- a/libtirpc/src/rtime.c
  144. +++ b/libtirpc/src/rtime.c
  145. @@ -123,7 +123,7 @@ rtime(addrp, timep, timeout)
  146.                         return(-1);    
  147.                 }
  148.         } else {
  149. -               if (connect(_get_osfhandle(s), (struct sockaddr *)addrp, sizeof(*addrp)) == SOCKET_ERROR) {
  150. +               if (wintirpc_connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) == SOCKET_ERROR) {
  151.                         do_close(s);
  152.                         return(-1);
  153.                 }
  154. diff --git a/libtirpc/src/svc_generic.c b/libtirpc/src/svc_generic.c
  155. index 7ba0bfc..24b0479 100644
  156. --- a/libtirpc/src/svc_generic.c
  157. +++ b/libtirpc/src/svc_generic.c
  158. @@ -224,7 +224,7 @@ svc_tli_create(fd, nconf, bindaddr, sendsz, recvsz)
  159.                         if (bindresvport(fd, NULL) < 0) {
  160.                                 memset(&ss, 0, sizeof ss);
  161.                                 ss.ss_family = si.si_af;
  162. -                               if (bind(_get_osfhandle(fd), (struct sockaddr *)(void *)&ss,
  163. +                               if (wintirpc_bind(fd, (struct sockaddr *)(void *)&ss,
  164.                                     (socklen_t)si.si_alen) == SOCKET_ERROR) {
  165.                                         warnx(
  166.                                                 "svc_tli_create: could not bind to anonymous port");
  167. @@ -233,7 +233,7 @@ svc_tli_create(fd, nconf, bindaddr, sendsz, recvsz)
  168.                         }
  169.                         wintirpc_listen(fd, SOMAXCONN);
  170.                 } else {
  171. -                       if (bind(_get_osfhandle(fd),
  172. +                       if (wintirpc_bind(fd,
  173.                             (struct sockaddr *)bindaddr->addr.buf,
  174.                             (socklen_t)si.si_alen) == SOCKET_ERROR) {
  175.                                 warnx(
  176. diff --git a/libtirpc/src/wintirpc.c b/libtirpc/src/wintirpc.c
  177. index 53f6eab..47f0c96 100644
  178. --- a/libtirpc/src/wintirpc.c
  179. +++ b/libtirpc/src/wintirpc.c
  180. @@ -335,6 +335,16 @@ int wintirpc_accept(int in_s_fd, struct sockaddr *addr, int *addrlen)
  181.         return out_s_fd;
  182.  }
  183.  
  184. +int wintirpc_bind(int s, const struct sockaddr *name, socklen_t namelen)
  185. +{
  186. +    return bind(_get_osfhandle(s), name, namelen);
  187. +}
  188. +
  189. +int wintirpc_connect(int s, const struct sockaddr *name, socklen_t namelen)
  190. +{
  191. +    return connect(_get_osfhandle(s), name, namelen);
  192. +}
  193. +
  194.  wintirpc_ssize_t wintirpc_send(int s, const char *buf, size_t len, int flags)
  195.  {
  196.         /* handle type overflow |size_t| ---> |int| */
  197. diff --git a/libtirpc/tirpc/wintirpc.h b/libtirpc/tirpc/wintirpc.h
  198. index 4cb145f..fbf7c66 100644
  199. --- a/libtirpc/tirpc/wintirpc.h
  200. +++ b/libtirpc/tirpc/wintirpc.h
  201. @@ -141,6 +141,8 @@ int wintirpc_closesocket(int in_fd);
  202.  int wintirpc_close(int in_fd);
  203.  int wintirpc_listen(int in_s, int backlog);
  204.  int wintirpc_accept(int s_fd, struct sockaddr *addr, int *addrlen);
  205. +int wintirpc_bind(int s, const struct sockaddr *name, socklen_t namelen);
  206. +int wintirpc_connect(int s, const struct sockaddr *name, socklen_t namelen);
  207.  wintirpc_ssize_t wintirpc_send(int s, const char *buf, size_t len,
  208.      int flags);
  209.  wintirpc_ssize_t wintirpc_sendto(int s, const char *buf, size_t len,
  210. --
  211. 2.43.0
  212.  
  213. From bd608e2ad37f2be7d899c54d912a4f0a8d82c56b Mon Sep 17 00:00:00 2001
  214. From: Roland Mainz <roland.mainz@nrubsig.org>
  215. Date: Mon, 4 Mar 2024 19:12:31 +0100
  216. Subject: [PATCH 2/3] libtirpc: Add wintirpc wrappers for
  217.  |getsockopt|+|setsockopt()|
  218.  
  219. Add wintirpc wrappers for |getsockopt()|--->|wintirpc_getsockopt()|
  220. and |setsockopt()|--->|wintirpc_setsockopt()|.
  221.  
  222. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  223. ---
  224. libtirpc/src/bindresvport.c |  8 ++++----
  225.  libtirpc/src/clnt_bcast.c   |  4 ++--
  226.  libtirpc/src/clnt_dg.c      |  2 +-
  227.  libtirpc/src/clnt_generic.c |  2 +-
  228.  libtirpc/src/getpeereid.c   |  2 +-
  229.  libtirpc/src/rpc_generic.c  |  6 +++---
  230.  libtirpc/src/svc_vc.c       |  2 +-
  231.  libtirpc/src/wintirpc.c     | 22 ++++++++++++++++++----
  232.  libtirpc/tirpc/wintirpc.h   |  4 ++++
  233.  9 files changed, 35 insertions(+), 17 deletions(-)
  234.  
  235. diff --git a/libtirpc/src/bindresvport.c b/libtirpc/src/bindresvport.c
  236. index d33deb7..01d1921 100644
  237. --- a/libtirpc/src/bindresvport.c
  238. +++ b/libtirpc/src/bindresvport.c
  239. @@ -185,7 +185,7 @@ bindresvport_sa(sd, sa)
  240.  
  241.  #ifdef _WIN32
  242.                 memset(sa, 0, salen);
  243. -               if (error = getsockopt(_get_osfhandle(sd), SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
  244. +               if (error = wintirpc_getsockopt(sd, SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
  245.                         int sockerr = WSAGetLastError();
  246.                         return -1;
  247.                 }
  248. @@ -231,11 +231,11 @@ bindresvport_sa(sd, sa)
  249.         if (*portp == 0) {
  250.                 socklen_t oldlen = sizeof(old);
  251.  
  252. -               error = getsockopt(_get_osfhandle(sd), proto, portrange, &old, &oldlen);
  253. +               error = wintirpc_getsockopt(sd, proto, portrange, &old, &oldlen);
  254.                 if (error < 0)
  255.                         return (error);
  256.  
  257. -               error = setsockopt(_get_osfhandle(sd), proto, portrange, &portlow,
  258. +               error = wintirpc_setsockopt(sd, proto, portrange, &portlow,
  259.                                 sizeof(portlow));
  260.                 if (error < 0)
  261.                         return (error);
  262. @@ -252,7 +252,7 @@ bindresvport_sa(sd, sa)
  263.                 int saved_errno = errno;
  264.  
  265.                 if (error < 0) {
  266. -                       if (setsockopt(_get_osfhandle(sd), proto, portrange, &old,
  267. +                       if (wintirpc_setsockopt(sd, proto, portrange, &old,
  268.                                 sizeof(old)) < 0)
  269.                         errno = saved_errno;
  270.                         return (error);
  271. diff --git a/libtirpc/src/clnt_bcast.c b/libtirpc/src/clnt_bcast.c
  272. index 6ee6e60..411a3b2 100644
  273. --- a/libtirpc/src/clnt_bcast.c
  274. +++ b/libtirpc/src/clnt_bcast.c
  275. @@ -249,12 +249,12 @@ __rpc_broadenable(int af, int s, struct broadif *bip)
  276.  #if 0
  277.         if (af == AF_INET6) {
  278.                 fprintf(stderr, "set v6 multicast if to %d\n", bip->index);
  279. -               if (setsockopt(_get_osfhandle(s), IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
  280. +               if (wintirpc_setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
  281.                         sizeof bip->index) < 0)
  282.                         return -1;
  283.         } else
  284.  #endif
  285. -               if (setsockopt(_get_osfhandle(s), SOL_SOCKET, SO_BROADCAST, &o, sizeof o) == SOCKET_ERROR)
  286. +               if (wintirpc_setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) == SOCKET_ERROR)
  287.                         return -1;
  288.  
  289.         return 0;
  290. diff --git a/libtirpc/src/clnt_dg.c b/libtirpc/src/clnt_dg.c
  291. index 7541656..de318e6 100644
  292. --- a/libtirpc/src/clnt_dg.c
  293. +++ b/libtirpc/src/clnt_dg.c
  294. @@ -281,7 +281,7 @@ clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz)
  295.  #ifdef IP_RECVERR
  296.         {
  297.         int on = 1;
  298. -       setsockopt(_get_osfhandle(fd), SOL_IP, IP_RECVERR, &on, sizeof(on));
  299. +       wintirpc_setsockopt(fd, SOL_IP, IP_RECVERR, &on, sizeof(on));
  300.         }
  301.  #endif
  302.         ioctlsocket(_get_osfhandle(fd), FIONBIO, &one);
  303. diff --git a/libtirpc/src/clnt_generic.c b/libtirpc/src/clnt_generic.c
  304. index 92ec08d..a7756bb 100644
  305. --- a/libtirpc/src/clnt_generic.c
  306. +++ b/libtirpc/src/clnt_generic.c
  307. @@ -404,7 +404,7 @@ clnt_tli_create(const int fd_in, const struct netconfig *nconf,
  308.                 if (nconf &&
  309.                     ((strcmp(nconf->nc_protofmly, "inet") == 0) ||
  310.                      (strcmp(nconf->nc_protofmly, "inet6") == 0))) {
  311. -                       setsockopt(_get_osfhandle(fd), IPPROTO_TCP, TCP_NODELAY, (const char *)&one,
  312. +                       wintirpc_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&one,
  313.                             sizeof (one));
  314.                 }
  315.                 cl = clnt_vc_create(fd, svcaddr, prog, vers, sendsz, recvsz,
  316. diff --git a/libtirpc/src/getpeereid.c b/libtirpc/src/getpeereid.c
  317. index 17b1a5c..c328b9c 100644
  318. --- a/libtirpc/src/getpeereid.c
  319. +++ b/libtirpc/src/getpeereid.c
  320. @@ -50,7 +50,7 @@ getpeereid(int s, uid_t *euid, gid_t *egid)
  321.         int error;
  322.  
  323.         uclen = sizeof(uc);
  324. -       error = getsockopt(_get_osfhandle(s), SOL_SOCKET, SO_PEERCRED, &uc, &uclen); /*  SCM_CREDENTIALS */
  325. +       error = wintirpc_getsockopt(s, SOL_SOCKET, SO_PEERCRED, &uc, &uclen); /*  SCM_CREDENTIALS */
  326.         if (error != 0)
  327.                 return (error);
  328.         //      if (uc.cr_version != XUCRED_VERSION)
  329. diff --git a/libtirpc/src/rpc_generic.c b/libtirpc/src/rpc_generic.c
  330. index 9491761..e5c8274 100644
  331. --- a/libtirpc/src/rpc_generic.c
  332. +++ b/libtirpc/src/rpc_generic.c
  333. @@ -490,7 +490,7 @@ __rpc_fd2sockinfo(int fd, struct __rpc_sockinfo *sip)
  334.  #ifdef _WIN32
  335.         WSAPROTOCOL_INFO proto_info;
  336.         int proto_info_size = sizeof(proto_info);
  337. -       if (getsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
  338. +       if (wintirpc_getsockopt(fd, SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
  339.                 int err = WSAGetLastError();
  340.                 return 0;
  341.         }
  342. @@ -505,7 +505,7 @@ __rpc_fd2sockinfo(int fd, struct __rpc_sockinfo *sip)
  343.         sip->si_alen = len;
  344.  
  345.         len = sizeof type;
  346. -       if (getsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_TYPE, (char *)&type, &len) == SOCKET_ERROR) {
  347. +       if (wintirpc_getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&type, &len) == SOCKET_ERROR) {
  348.                 int err = WSAGetLastError();
  349.                 return 0;
  350.         }
  351. @@ -570,7 +570,7 @@ __rpc_nconf2fd(const struct netconfig *nconf)
  352.             si.si_af == AF_INET6) {
  353.                 int val = 1;
  354.  
  355. -               setsockopt(_get_osfhandle(fd), SOL_IPV6, IPV6_V6ONLY, (const char *)&val, sizeof(val));
  356. +               wintirpc_setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, (const char *)&val, sizeof(val));
  357.         }
  358.         return fd;
  359.  }
  360. diff --git a/libtirpc/src/svc_vc.c b/libtirpc/src/svc_vc.c
  361. index 5345d4a..83c58fe 100644
  362. --- a/libtirpc/src/svc_vc.c
  363. +++ b/libtirpc/src/svc_vc.c
  364. @@ -359,7 +359,7 @@ again:
  365.         if (__rpc_fd2sockinfo(sock, &si) && si.si_proto == IPPROTO_TCP) {
  366.                 len = 1;
  367.                 /* XXX fvdl - is this useful? */
  368. -               setsockopt(_get_osfhandle(sock), IPPROTO_TCP, TCP_NODELAY, (const char *)&len, sizeof (len));
  369. +               wintirpc_setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&len, sizeof (len));
  370.         }
  371.  
  372.         cd = (struct cf_conn *)newxprt->xp_p1;
  373. diff --git a/libtirpc/src/wintirpc.c b/libtirpc/src/wintirpc.c
  374. index 47f0c96..003958a 100644
  375. --- a/libtirpc/src/wintirpc.c
  376. +++ b/libtirpc/src/wintirpc.c
  377. @@ -337,12 +337,12 @@ int wintirpc_accept(int in_s_fd, struct sockaddr *addr, int *addrlen)
  378.  
  379.  int wintirpc_bind(int s, const struct sockaddr *name, socklen_t namelen)
  380.  {
  381. -    return bind(_get_osfhandle(s), name, namelen);
  382. +       return bind(_get_osfhandle(s), name, namelen);
  383.  }
  384.  
  385.  int wintirpc_connect(int s, const struct sockaddr *name, socklen_t namelen)
  386.  {
  387. -    return connect(_get_osfhandle(s), name, namelen);
  388. +       return connect(_get_osfhandle(s), name, namelen);
  389.  }
  390.  
  391.  wintirpc_ssize_t wintirpc_send(int s, const char *buf, size_t len, int flags)
  392. @@ -368,8 +368,8 @@ wintirpc_ssize_t wintirpc_recv(int socket, void *buffer, size_t length, int flag
  393.  }
  394.  
  395.  wintirpc_ssize_t wintirpc_recvfrom(int socket, void *restrict buffer, size_t length,
  396. -           int flags, struct sockaddr *restrict address,
  397. -           socklen_t *restrict address_len)
  398. +       int flags, struct sockaddr *restrict address,
  399. +       socklen_t *restrict address_len)
  400.  {
  401.         /* handle type overflow |size_t| ---> |int| */
  402.         assert(length < INT_MAX);
  403. @@ -382,6 +382,20 @@ int wintirpc_getsockname(int s, struct sockaddr *name, int *namelen)
  404.         return getsockname(_get_osfhandle(s), name, namelen);
  405.  }
  406.  
  407. +int wintirpc_getsockopt(int socket, int level, int option_name,
  408. +       void *restrict option_value, socklen_t *restrict option_len)
  409. +{
  410. +       return getsockopt(_get_osfhandle(socket), level, option_name,
  411. +               option_value, option_len);
  412. +}
  413. +
  414. +int wintirpc_setsockopt(int socket, int level, int option_name,
  415. +       const void *option_value, socklen_t option_len)
  416. +{
  417. +       return setsockopt(_get_osfhandle(socket), level, option_name,
  418. +               option_value, option_len);
  419. +}
  420. +
  421.  void wintirpc_syslog(int prio, const char *format, ...)
  422.  {
  423.         const char *prio_s;
  424. diff --git a/libtirpc/tirpc/wintirpc.h b/libtirpc/tirpc/wintirpc.h
  425. index fbf7c66..c1f7f22 100644
  426. --- a/libtirpc/tirpc/wintirpc.h
  427. +++ b/libtirpc/tirpc/wintirpc.h
  428. @@ -153,6 +153,10 @@ wintirpc_ssize_t wintirpc_recvfrom(int socket, void *restrict buffer,
  429.      size_t length, int flags, struct sockaddr *restrict address,
  430.      socklen_t *restrict address_len);
  431.  int wintirpc_getsockname(int s, struct sockaddr *name, int *namelen);
  432. +int wintirpc_getsockopt(int socket, int level, int option_name,
  433. +    void *restrict option_value, socklen_t *restrict option_len);
  434. +int wintirpc_setsockopt(int socket, int level, int option_name,
  435. +    const void *option_value, socklen_t option_len);
  436.  void wintirpc_syslog(int prio, const char *format, ...);
  437.  void wintirpc_warnx(const char *format, ...);
  438.  void wintirpc_register_osfhandle_fd(SOCKET handle, int fd);
  439. --
  440. 2.43.0
  441.  
  442. From 87108a78b5de3a87efb65fcc061a47246a41ee38 Mon Sep 17 00:00:00 2001
  443. From: Roland Mainz <roland.mainz@nrubsig.org>
  444. Date: Mon, 4 Mar 2024 19:16:01 +0100
  445. Subject: [PATCH 3/3] daemon: More workarounds/hacks for
  446.  getattr-afer-file-close
  447.  
  448. More work on the workarounds/hacks for the getattr-afer-file-close
  449. issue.
  450.  
  451. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  452. ---
  453. daemon/getattr.c       | 19 ++++++-----------
  454.  daemon/nfs41.h         |  5 ++++-
  455.  daemon/nfs41_session.c |  7 ++++++
  456.  daemon/open.c          | 48 ++++++++++++++++++++++++++++++++++++++++++
  457.  daemon/upcall.c        | 16 +++++++++++++-
  458.  5 files changed, 80 insertions(+), 15 deletions(-)
  459.  
  460. diff --git a/daemon/getattr.c b/daemon/getattr.c
  461. index 9cfb00d..7975cc8 100644
  462. --- a/daemon/getattr.c
  463. +++ b/daemon/getattr.c
  464. @@ -82,25 +82,18 @@ static int parse_getattr(unsigned char *buffer, uint32_t length, nfs41_upcall *u
  465.          goto out;
  466.      }
  467.  
  468. -    /*
  469. -     * If |upcall->state_ref| is garbage, then this should trigger
  470. -     * an exception
  471. -     */
  472. -    volatile int ok = 0;
  473. -    __try {
  474. -        if (upcall->state_ref->session->client != NULL)
  475. -            ok++;
  476. -    }
  477. -    __except(EXCEPTION_EXECUTE_HANDLER) {
  478. -        eprintf("parse_getattr: Exception accessing "
  479. +    if (!isvalidnfs41_open_state_ptr(upcall->state_ref)) {
  480. +        eprintf("parse_getattr: Error accessing "
  481.              "upcall->state_ref(=0x%p)->session->client\n",
  482.              upcall->state_ref);
  483. -    }
  484. -    if (ok != 1) {
  485.          status = ERROR_INVALID_PARAMETER;
  486.          goto out;
  487.      }
  488.      EASSERT(upcall->state_ref->ref_count > 0);
  489. +    if (upcall->state_ref->ref_count == 0) {
  490. +        status = ERROR_INVALID_PARAMETER;
  491. +        goto out;
  492. +    }
  493.  #endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
  494.  
  495.      getattr_upcall_args *args = &upcall->args.getattr;
  496. diff --git a/daemon/nfs41.h b/daemon/nfs41.h
  497. index 53dec06..1c2be42 100644
  498. --- a/daemon/nfs41.h
  499. +++ b/daemon/nfs41.h
  500. @@ -23,6 +23,7 @@
  501.  #ifndef __NFS41__
  502.  #define __NFS41__
  503.  
  504. +#include <stdbool.h>
  505.  #include "util.h"
  506.  #include "list.h"
  507.  
  508. @@ -538,7 +539,9 @@ void nfs41_open_state_ref(
  509.  
  510.  void nfs41_open_state_deref(
  511.      IN nfs41_open_state *state);
  512. -
  513. +#ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
  514. +bool isvalidnfs41_open_state_ptr(nfs41_open_state *state_ref);
  515. +#endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
  516.  struct __stateid_arg;
  517.  void nfs41_open_stateid_arg(
  518.      IN nfs41_open_state *state,
  519. diff --git a/daemon/nfs41_session.c b/daemon/nfs41_session.c
  520. index d7e5011..1447ab7 100644
  521. --- a/daemon/nfs41_session.c
  522. +++ b/daemon/nfs41_session.c
  523. @@ -24,6 +24,7 @@
  524.  #include <process.h>
  525.  #include <stdio.h>
  526.  
  527. +#include "nfs41_build_features.h"
  528.  #include "nfs41_ops.h"
  529.  #include "nfs41_callback.h"
  530.  #include "util.h"
  531. @@ -442,5 +443,11 @@ void nfs41_session_free(
  532.      }
  533.      DeleteCriticalSection(&session->table.lock);
  534.      ReleaseSRWLockExclusive(&session->client->session_lock);
  535. +
  536. +#ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
  537. +    (void)memset(session, 0, sizeof(nfs41_session));
  538. +    debug_delayed_free(session);
  539. +#else
  540.      free(session);
  541. +#endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
  542.  }
  543. diff --git a/daemon/open.c b/daemon/open.c
  544. index 3342fb1..4c739ae 100644
  545. --- a/daemon/open.c
  546. +++ b/daemon/open.c
  547. @@ -121,6 +121,47 @@ static void open_state_free(
  548.  #endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
  549.  }
  550.  
  551. +#ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
  552. +bool isvalidnfs41_open_state_ptr(nfs41_open_state *state_ref)
  553. +{
  554. +    /*
  555. +     * If |>state_ref| is garbage, then this should trigger
  556. +     * an exception
  557. +     */
  558. +    volatile int mark = 0;
  559. +    __try {
  560. +        if (state_ref != NULL) {
  561. +            mark++;
  562. +            if (DEBUG_IS_VALID_NON_NULL_PTR(state_ref)) {
  563. +                mark++;
  564. +                if (state_ref->session != NULL) {
  565. +                    mark++;
  566. +                    if (DEBUG_IS_VALID_NON_NULL_PTR(state_ref->session)) {
  567. +                        mark++;
  568. +                        if (state_ref->session->client != NULL) {
  569. +                            mark++;
  570. +                            if (DEBUG_IS_VALID_NON_NULL_PTR(state_ref->session->client)) {
  571. +                                mark++;
  572. +                            }
  573. +                        }
  574. +                    }
  575. +                }
  576. +            }
  577. +        }
  578. +    } __except(EXCEPTION_EXECUTE_HANDLER) {
  579. +        eprintf("isvalidnfs41_open_state_ptr: Exception accessing "
  580. +            "state_ref(=0x%p)->session->client, mark=%d\n",
  581. +            state_ref, mark);
  582. +    }
  583. +
  584. +    if (mark == 6) {
  585. +        return true;
  586. +    }
  587. +
  588. +    return false;
  589. +}
  590. +#endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
  591. +
  592.  /* open state reference counting */
  593.  void nfs41_open_state_ref(
  594.      IN nfs41_open_state *state)
  595. @@ -1116,6 +1157,13 @@ out:
  596.  
  597.  static void cleanup_close(nfs41_upcall *upcall)
  598.  {
  599. +#ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
  600. +    EASSERT(upcall->state_ref != INVALID_HANDLE_VALUE);
  601. +    if (upcall->state_ref == INVALID_HANDLE_VALUE) {
  602. +        return;
  603. +    }
  604. +#endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
  605. +
  606.      /* release the initial reference from create_open_state() */
  607.      nfs41_open_state_deref(upcall->state_ref);
  608.  }
  609. diff --git a/daemon/upcall.c b/daemon/upcall.c
  610. index 82fc5d2..126e740 100644
  611. --- a/daemon/upcall.c
  612. +++ b/daemon/upcall.c
  613. @@ -122,8 +122,22 @@ int upcall_parse(
  614.  
  615.  #ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
  616.      if (upcall->state_ref != INVALID_HANDLE_VALUE) {
  617. +        if (!isvalidnfs41_open_state_ptr(upcall->state_ref)) {
  618. +            eprintf("upcall_parse: Error accessing "
  619. +                "upcall->state_ref(=0x%p), opcode %d; "
  620. +                "returning ERROR_INVALID_PARAMETER\n",
  621. +                upcall->state_ref, upcall->opcode);
  622. +            /*
  623. +             * Set |upcall->state_ref| to |INVALID_HANDLE_VALUE|
  624. +             * so that we do not try to dereference it
  625. +             */
  626. +            upcall->state_ref = INVALID_HANDLE_VALUE;
  627. +            status = ERROR_INVALID_PARAMETER;
  628. +            goto out;
  629. +        }
  630. +
  631.          if (upcall->state_ref->ref_count == 0) {
  632. -            eprintf("upcall->state_ref(=0x%p).ref_count == 0, "
  633. +            eprintf("upcall_parse: upcall->state_ref(=0x%p).ref_count == 0, "
  634.                  "opcode %d; returning ERROR_INVALID_PARAMETER\n",
  635.                  upcall->state_ref, upcall->opcode);
  636.              /*
  637. --
  638. 2.43.0

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at