- From 32854f48fa3bd7ffe8c79578fa584796c23b2c94 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Wed, 15 Nov 2023 10:53:51 +0100
- Subject: [PATCH 1/4] libtirpc: Implement |wintirpc_syslog()| and reenable
- |syslog()|
- Implement |wintirpc_syslog()| and reenable |syslog()| in libtirpc
- code so we get better diagnostics - and error messages when
- C:\etc\netconfig cannot be opened.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- libtirpc/src/auth_des.c | 36 +++++++++++++++++++-----------------
- libtirpc/src/auth_time.c | 7 ++++---
- libtirpc/src/clnt_generic.c | 4 +++-
- libtirpc/src/clnt_vc.c | 8 +++++---
- libtirpc/src/getnetpath.c | 8 +++++---
- libtirpc/src/rpc_generic.c | 8 +++++---
- libtirpc/src/rpc_soc.c | 11 ++++++-----
- libtirpc/src/rpcb_clnt.c | 6 ++++--
- libtirpc/src/wintirpc.c | 28 +++++++++++++++++++++++++++-
- libtirpc/tirpc/wintirpc.h | 19 +++++++++++++++++++
- 10 files changed, 97 insertions(+), 38 deletions(-)
- diff --git a/libtirpc/src/auth_des.c b/libtirpc/src/auth_des.c
- index b515a0c..76bb9a4 100644
- --- a/libtirpc/src/auth_des.c
- +++ b/libtirpc/src/auth_des.c
- @@ -42,7 +42,9 @@
- //#include <unistd.h>
- //#include <sys/cdefs.h>
- #include <rpc/des_crypt.h>
- -//#include <syslog.h>
- +#ifndef _WIN32
- +#include <syslog.h>
- +#endif
- #include <rpc/types.h>
- #include <rpc/auth.h>
- #include <rpc/auth_des.h>
- @@ -128,9 +130,9 @@ authdes_seccreate(const char *servername, const u_int win,
- AUTH *dummy;
- if (! getpublickey(servername, (char *) pkey_data)) {
- - //syslog(LOG_ERR,
- - // "authdes_seccreate: no public key found for %s",
- - // servername);
- + syslog(LOG_ERR,
- + "authdes_seccreate: no public key found for %s",
- + servername);
- return (NULL);
- }
- @@ -159,12 +161,12 @@ authdes_pk_seccreate(const char *servername, netobj *pkey, u_int window,
- */
- auth = ALLOC(AUTH);
- if (auth == NULL) {
- - //syslog(LOG_ERR, "authdes_pk_seccreate: out of memory");
- + syslog(LOG_ERR, "authdes_pk_seccreate: out of memory");
- return (NULL);
- }
- ad = ALLOC(struct ad_private);
- if (ad == NULL) {
- - //syslog(LOG_ERR, "authdes_pk_seccreate: out of memory");
- + syslog(LOG_ERR, "authdes_pk_seccreate: out of memory");
- goto failed;
- }
- ad->ad_fullname = ad->ad_servername = NULL; /* Sanity reasons */
- @@ -183,13 +185,13 @@ authdes_pk_seccreate(const char *servername, netobj *pkey, u_int window,
- ad->ad_servername = (char *)mem_alloc(ad->ad_servernamelen + 1);
- if (ad->ad_fullname == NULL || ad->ad_servername == NULL) {
- - //syslog(LOG_ERR, "authdes_seccreate: out of memory");
- + syslog(LOG_ERR, "authdes_seccreate: out of memory");
- goto failed;
- }
- if (timehost != NULL) {
- ad->ad_timehost = (char *)mem_alloc(strlen(timehost) + 1);
- if (ad->ad_timehost == NULL) {
- - //syslog(LOG_ERR, "authdes_seccreate: out of memory");
- + syslog(LOG_ERR, "authdes_seccreate: out of memory");
- goto failed;
- }
- memcpy(ad->ad_timehost, timehost, strlen(timehost) + 1);
- @@ -205,8 +207,8 @@ authdes_pk_seccreate(const char *servername, netobj *pkey, u_int window,
- ad->ad_window = window;
- if (ckey == NULL) {
- if (key_gendes(&auth->ah_key) < 0) {
- - //syslog(LOG_ERR,
- - // "authdes_seccreate: keyserv(1m) is unable to generate session key");
- + syslog(LOG_ERR,
- + "authdes_seccreate: keyserv(1m) is unable to generate session key");
- goto failed;
- }
- } else {
- @@ -310,7 +312,7 @@ authdes_marshal(AUTH *auth, XDR *xdrs)
- DES_ENCRYPT | DES_HW);
- }
- if (DES_FAILED(status)) {
- - //syslog(LOG_ERR, "authdes_marshal: DES encryption failure");
- + syslog(LOG_ERR, "authdes_marshal: DES encryption failure");
- return (FALSE);
- }
- ad->ad_verf.adv_xtimestamp = cryptbuf[0];
- @@ -383,7 +385,7 @@ authdes_validate(AUTH *auth, struct opaque_auth *rverf)
- (u_int)sizeof (des_block), DES_DECRYPT | DES_HW);
- if (DES_FAILED(status)) {
- - //syslog(LOG_ERR, "authdes_validate: DES decryption failure");
- + syslog(LOG_ERR, "authdes_validate: DES decryption failure");
- return (FALSE);
- }
- @@ -400,7 +402,7 @@ authdes_validate(AUTH *auth, struct opaque_auth *rverf)
- */
- if (bcmp((char *)&ad->ad_timestamp, (char *)&verf.adv_timestamp,
- sizeof(struct timeval)) != 0) {
- - //syslog(LOG_DEBUG, "authdes_validate: verifier mismatch");
- + syslog(LOG_DEBUG, "authdes_validate: verifier mismatch");
- return (FALSE);
- }
- @@ -438,16 +440,16 @@ authdes_refresh(AUTH *auth, void *dummy)
- * Hope the clocks are synced!
- */
- ad->ad_dosync = 0;
- - //syslog(LOG_DEBUG,
- - // "authdes_refresh: unable to synchronize clock");
- + syslog(LOG_DEBUG,
- + "authdes_refresh: unable to synchronize clock");
- }
- }
- ad->ad_xkey = auth->ah_key;
- pkey.n_bytes = (char *)(ad->ad_pkey);
- pkey.n_len = (u_int)strlen((char *)ad->ad_pkey) + 1;
- if (key_encryptsession_pk(ad->ad_servername, &pkey, &ad->ad_xkey) < 0) {
- - //syslog(LOG_INFO,
- - // "authdes_refresh: keyserv(1m) is unable to encrypt session key");
- + syslog(LOG_INFO,
- + "authdes_refresh: keyserv(1m) is unable to encrypt session key");
- return (FALSE);
- }
- cred->adc_fullname.key = ad->ad_xkey;
- diff --git a/libtirpc/src/auth_time.c b/libtirpc/src/auth_time.c
- index acf5e0e..99db3f8 100644
- --- a/libtirpc/src/auth_time.c
- +++ b/libtirpc/src/auth_time.c
- @@ -27,7 +27,9 @@
- //#include <sys/cdefs.h>
- #include <wintirpc.h>
- -//#include <syslog.h>
- +#ifndef _WIN32
- +#include <syslog.h>
- +#endif
- #include <string.h>
- #include <stdlib.h>
- //#include <unistd.h>
- @@ -48,8 +50,7 @@
- #ifdef TESTING
- -#define msg(x) printf("ERROR: %s\n", x)
- -/* #define msg(x) syslog(LOG_ERR, "%s", x) */
- +#define msg(x) syslog(LOG_ERR, "%s", x)
- #else
- #define msg(x)
- #endif
- diff --git a/libtirpc/src/clnt_generic.c b/libtirpc/src/clnt_generic.c
- index 6473b13..60cf026 100644
- --- a/libtirpc/src/clnt_generic.c
- +++ b/libtirpc/src/clnt_generic.c
- @@ -66,7 +66,9 @@
- #include <string.h>
- #include <stdlib.h>
- //#include <netdb.h>
- -//#include <syslog.h>
- +#ifndef _WIN32
- +#include <syslog.h>
- +#endif
- #include <rpc/rpc.h>
- #include <rpc/nettype.h>
- //#include <unistd.h>
- diff --git a/libtirpc/src/clnt_vc.c b/libtirpc/src/clnt_vc.c
- index bac4212..3adef9c 100644
- --- a/libtirpc/src/clnt_vc.c
- +++ b/libtirpc/src/clnt_vc.c
- @@ -72,7 +72,9 @@
- #include <reentrant.h>
- #include <sys/types.h>
- //#include <sys/poll.h>
- -//#include <sys/syslog.h>
- +#ifndef _WIN32
- +#include <sys/syslog.h>
- +#endif
- //#include <sys/un.h>
- //#include <sys/uio.h>
- //#include <sys/socket.h>
- @@ -353,8 +355,8 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz, cb_xdr, cb_fn, cb_args)
- cl = (CLIENT *)mem_alloc(sizeof (*cl));
- ct = (struct ct_data *)mem_alloc(sizeof (*ct));
- if ((cl == (CLIENT *)NULL) || (ct == (struct ct_data *)NULL)) {
- -// (void) syslog(LOG_ERR, clnt_vc_errstr,
- -// clnt_vc_str, __no_mem_str);
- + (void) syslog(LOG_ERR, clnt_vc_errstr,
- + clnt_vc_str, __no_mem_str);
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
- goto err;
- diff --git a/libtirpc/src/getnetpath.c b/libtirpc/src/getnetpath.c
- index 1fb6a12..fa11be1 100644
- --- a/libtirpc/src/getnetpath.c
- +++ b/libtirpc/src/getnetpath.c
- @@ -38,7 +38,9 @@
- #include <netconfig.h>
- #include <stdlib.h>
- #include <string.h>
- -//#include <syslog.h>
- +#ifndef _WIN32
- +#include <syslog.h>
- +#endif
- /*
- * internal structure to keep track of a netpath "session"
- @@ -90,7 +92,7 @@ setnetpath()
- return (NULL);
- }
- if ((np_sessionp->nc_handlep = setnetconfig()) == NULL) {
- - //syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- + syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- return (NULL);
- }
- np_sessionp->valid = NP_VALID;
- @@ -148,7 +150,7 @@ getnetpath(handlep)
- if (np_sessionp->nc_handlep == NULL) {
- np_sessionp->nc_handlep = setnetconfig();
- if (np_sessionp->nc_handlep == NULL) {
- - //syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- + syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- }
- }
- if ((ncp = getnetconfig(np_sessionp->nc_handlep)) == NULL) {
- diff --git a/libtirpc/src/rpc_generic.c b/libtirpc/src/rpc_generic.c
- index 8ac2063..de8281a 100644
- --- a/libtirpc/src/rpc_generic.c
- +++ b/libtirpc/src/rpc_generic.c
- @@ -54,7 +54,9 @@
- #include <netconfig.h>
- #include <stdlib.h>
- #include <string.h>
- -//#include <syslog.h>
- +#ifndef _WIN32
- +#include <syslog.h>
- +#endif
- #include <rpc/nettype.h>
- #include "rpc_com.h"
- @@ -262,7 +264,7 @@ __rpc_getconfip(nettype)
- void *confighandle;
- if (!(confighandle = setnetconfig())) {
- - //syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- + syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- return (NULL);
- }
- while ((nconf = getnetconfig(confighandle)) != NULL) {
- @@ -328,7 +330,7 @@ __rpc_setconf(nettype)
- case _RPC_TCP:
- case _RPC_UDP:
- if (!(handle->nhandle = setnetconfig())) {
- - //syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- + syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- free(handle);
- return (NULL);
- }
- diff --git a/libtirpc/src/rpc_soc.c b/libtirpc/src/rpc_soc.c
- index 0cbb749..d7faf25 100644
- --- a/libtirpc/src/rpc_soc.c
- +++ b/libtirpc/src/rpc_soc.c
- @@ -53,11 +53,12 @@
- #include <rpc/pmap_clnt.h>
- #include <rpc/pmap_prot.h>
- #include <rpc/nettype.h>
- -//#include <syslog.h>
- +#ifndef _WIN32
- +#include <syslog.h>
- +#endif
- //#include <netinet/in.h>
- //#include <netdb.h>
- #include <errno.h>
- -//#include <syslog.h>
- #include <stdlib.h>
- #include <string.h>
- //#include <unistd.h>
- @@ -275,15 +276,15 @@ svc_com_create(fd, sendsize, recvsize, netid)
- struct sockaddr_in sin;
- if ((nconf = __rpc_getconfip(netid)) == NULL) {
- - //(void) syslog(LOG_ERR, "Could not get %s transport", netid);
- + (void) syslog(LOG_ERR, "Could not get %s transport", netid);
- return (NULL);
- }
- if (fd == RPC_ANYSOCK) {
- fd = __rpc_nconf2fd(nconf);
- if (fd == -1) {
- (void) freenetconfigent(nconf);
- - //(void) syslog(LOG_ERR,
- - //"svc%s_create: could not open connection", netid);
- + (void) syslog(LOG_ERR,
- + "svc%s_create: could not open connection", netid);
- return (NULL);
- }
- madefd = TRUE;
- diff --git a/libtirpc/src/rpcb_clnt.c b/libtirpc/src/rpcb_clnt.c
- index 61adb78..5fb5daa 100644
- --- a/libtirpc/src/rpcb_clnt.c
- +++ b/libtirpc/src/rpcb_clnt.c
- @@ -56,7 +56,9 @@
- #include <string.h>
- //#include <unistd.h>
- //#include <netdb.h>
- -//#include <syslog.h>
- +#ifndef _WIN32
- +#include <syslog.h>
- +#endif
- #include "rpc_com.h"
- @@ -470,7 +472,7 @@ try_nconf:
- nc_handle = setnetconfig();
- if (nc_handle == NULL) {
- /* fails to open netconfig file */
- - //syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- + syslog (LOG_ERR, "rpc: failed to open " NETCONFIG);
- rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
- mutex_unlock(&loopnconf_lock);
- return (NULL);
- diff --git a/libtirpc/src/wintirpc.c b/libtirpc/src/wintirpc.c
- index 4db1bb8..243eb17 100644
- --- a/libtirpc/src/wintirpc.c
- +++ b/libtirpc/src/wintirpc.c
- @@ -247,7 +247,7 @@ int wintirpc_socket(int af, int type, int protocol)
- wintirpc_register_osfhandle_fd(s, fd);
- - (void)fprintf(stderr, "wintirpc_socket: %s/%d: sock fd=%d\n",
- + (void)syslog(LOG_DEBUG, "wintirpc_socket: %s/%d: sock fd=%d",
- __FILE__, (int)__LINE__, fd);
- return fd;
- @@ -314,6 +314,32 @@ int wintirpc_sendto(int s, const char *buf, int len, int flags,
- return(sendto(_get_osfhandle(s), buf, len, flags, to, tolen));
- }
- +void wintirpc_syslog(int prio, const char *format, ...)
- +{
- + const char *prio_s;
- + va_list args;
- + va_start(args, format);
- +
- + switch (LOG_PRI(prio)) {
- + case LOG_EMERG: prio_s = "EMERG"; break;
- + case LOG_ALERT: prio_s = "ALERT"; break;
- + case LOG_CRIT: prio_s = "CRIT"; break;
- + case LOG_ERR: prio_s = "ERR"; break;
- + case LOG_WARNING: prio_s = "WARNING"; break;
- + case LOG_NOTICE: prio_s = "NOTICE"; break;
- + case LOG_INFO: prio_s = "INFO"; break;
- + case LOG_DEBUG: prio_s = "DEBUG"; break;
- + default: prio_s = "UNKNOWN_ERROR"; break;
- + }
- +
- + (void)fprintf(stderr, "%04x: %s: ", GetCurrentThreadId(), prio_s);
- + (void)vfprintf(stderr, format, args);
- + (void)fputc('\n', stderr);
- + (void)fflush(stderr);
- + va_end(args);
- +}
- +
- +
- void wintirpc_warnx(const char *format, ...)
- {
- va_list args;
- diff --git a/libtirpc/tirpc/wintirpc.h b/libtirpc/tirpc/wintirpc.h
- index 66a0f48..f5e5a9f 100644
- --- a/libtirpc/tirpc/wintirpc.h
- +++ b/libtirpc/tirpc/wintirpc.h
- @@ -131,6 +131,7 @@ int wintirpc_listen(int in_s, int backlog);
- int wintirpc_accept(int s_fd, struct sockaddr *addr, int *addrlen);
- int wintirpc_send(int s, const char *buf, int len, int flags);
- int wintirpc_sendto(int s, const char *buf, int len, int flags, const struct sockaddr *to, int tolen);
- +void wintirpc_syslog(int prio, const char *format, ...);
- void wintirpc_warnx(const char *format, ...);
- void wintirpc_register_osfhandle_fd(SOCKET handle, int fd);
- void wintirpc_unregister_osfhandle(SOCKET handle);
- @@ -147,5 +148,23 @@ void wintirpc_debug(char *fmt, ...);
- /* Mappings Windows API to |wintirpc_*()|-API */
- #define warnx wintirpc_warnx
- +#define syslog wintirpc_syslog
- +
- +/* syslog */
- +#ifndef LOG_EMERG
- +#define LOG_EMERG 0
- +#define LOG_ALERT 1
- +#define LOG_CRIT 2
- +#define LOG_ERR 3
- +#define LOG_WARNING 4
- +#define LOG_NOTICE 5
- +#define LOG_INFO 6
- +#define LOG_DEBUG 7
- +#endif /* !LOG_EMERG */
- +
- +#define _LOG_PRIMASK 0x07
- +
- +#define LOG_PRI(p) ((p) & _LOG_PRIMASK)
- +
- #endif /* !_TIRPC_WINTIRPC_H */
- --
- 2.42.1
- From 4a9b922c95ea583c0cd6d83f2f1a0b7c2f035f29 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Wed, 15 Nov 2023 11:59:05 +0100
- Subject: [PATCH 2/4] libtirpc: Use |close()| for sockets to stop leaking osf
- fds
- Use |close()| instead of |closesocket()| to stop leaking osf fd.
- This also adds a wrapper (|wintirpc_close()|) so we can keep
- track the closing of sockets wrapped by osf fds.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- libtirpc/src/auth_time.c | 4 ++--
- libtirpc/src/clnt_bcast.c | 4 ++--
- libtirpc/src/clnt_dg.c | 2 +-
- libtirpc/src/clnt_generic.c | 6 +++---
- libtirpc/src/clnt_vc.c | 5 +++--
- libtirpc/src/rpc_soc.c | 6 +++---
- libtirpc/src/rpcb_clnt.c | 8 ++++----
- libtirpc/src/rtime.c | 2 +-
- libtirpc/src/svc_dg.c | 2 +-
- libtirpc/src/svc_generic.c | 2 +-
- libtirpc/src/svc_vc.c | 2 +-
- libtirpc/src/wintirpc.c | 28 ++++++++++++++++++++++++++++
- libtirpc/tirpc/wintirpc.h | 2 ++
- 13 files changed, 52 insertions(+), 21 deletions(-)
- diff --git a/libtirpc/src/auth_time.c b/libtirpc/src/auth_time.c
- index 99db3f8..0079f12 100644
- --- a/libtirpc/src/auth_time.c
- +++ b/libtirpc/src/auth_time.c
- @@ -447,7 +447,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid)
- time_valid = 1;
- }
- save = WSAGetLastError();
- - (void)wintirpc_closesocket(s);
- + (void)wintirpc_close(s);
- errno = save;
- s = RPC_ANYSOCK;
- @@ -466,7 +466,7 @@ error:
- */
- if (s != RPC_ANYSOCK)
- - (void)wintirpc_closesocket(s);
- + (void)wintirpc_close(s);
- if (clnt != NULL)
- clnt_destroy(clnt);
- diff --git a/libtirpc/src/clnt_bcast.c b/libtirpc/src/clnt_bcast.c
- index 89b7c7c..6ee6e60 100644
- --- a/libtirpc/src/clnt_bcast.c
- +++ b/libtirpc/src/clnt_bcast.c
- @@ -378,7 +378,7 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
- if (si.si_af == AF_INET && si.si_proto == IPPROTO_UDP) {
- udpbufsz = fdlist[fdlistno].dsize;
- if ((outbuf_pmap = malloc(udpbufsz)) == NULL) {
- - wintirpc_closesocket(fd);
- + wintirpc_close(fd);
- stat = RPC_SYSTEMERROR;
- goto done_broad;
- }
- @@ -676,7 +676,7 @@ done_broad:
- (void) free(outbuf_pmap);
- #endif /* PORTMAP */
- for (i = 0; i < fdlistno; i++) {
- - (void)wintirpc_closesocket(fdlist[i].fd);
- + (void)wintirpc_close(fdlist[i].fd);
- __rpc_freebroadifs(&fdlist[i].nal);
- }
- AUTH_DESTROY(sys_auth);
- diff --git a/libtirpc/src/clnt_dg.c b/libtirpc/src/clnt_dg.c
- index 0e7427f..56492ee 100644
- --- a/libtirpc/src/clnt_dg.c
- +++ b/libtirpc/src/clnt_dg.c
- @@ -793,7 +793,7 @@ clnt_dg_destroy(cl)
- while (dg_fd_locks[cu_fd])
- cond_wait(&dg_cv[cu_fd], &clnt_fd_lock);
- if (cu->cu_closeit)
- - (void)wintirpc_closesocket(cu_fd);
- + (void)wintirpc_close(cu_fd);
- XDR_DESTROY(&(cu->cu_outxdrs));
- mem_free(cu, (sizeof (*cu) + cu->cu_sendsz + cu->cu_recvsz));
- if (cl->cl_netid && cl->cl_netid[0])
- diff --git a/libtirpc/src/clnt_generic.c b/libtirpc/src/clnt_generic.c
- index 60cf026..2fe0f97 100644
- --- a/libtirpc/src/clnt_generic.c
- +++ b/libtirpc/src/clnt_generic.c
- @@ -437,7 +437,7 @@ err:
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
- err1: if (madefd)
- - (void)wintirpc_closesocket(fd);
- + (void)wintirpc_close(fd);
- return (NULL);
- }
- @@ -462,11 +462,11 @@ __rpc_raise_fd(int fd)
- return (fd);
- if (fsync(nfd) == -1) {
- - wintirpc_closesocket(nfd);
- + wintirpc_close(nfd);
- return (fd);
- }
- - if (wintirpc_closesocket(fd) == -1) {
- + if (wintirpc_close(fd) == -1) {
- /* this is okay, we will syslog an error, then use the new fd */
- (void) syslog(LOG_ERR,
- "could not close() fd %d; mem & fd leak", fd);
- diff --git a/libtirpc/src/clnt_vc.c b/libtirpc/src/clnt_vc.c
- index 3adef9c..64e0d42 100644
- --- a/libtirpc/src/clnt_vc.c
- +++ b/libtirpc/src/clnt_vc.c
- @@ -459,7 +459,7 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz, cb_xdr, cb_fn, cb_args)
- XDR_ENCODE);
- if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
- if (ct->ct_closeit) {
- - (void)wintirpc_closesocket(fd);
- + (void)wintirpc_close(fd);
- }
- goto err;
- }
- @@ -935,7 +935,8 @@ clnt_vc_destroy(cl)
- }
- if (ct->ct_closeit && ct->ct_fd != -1) {
- - (void)wintirpc_closesocket(ct->ct_fd);
- + (void)wintirpc_close(ct->ct_fd);
- + ct->ct_fd = -1;
- }
- XDR_DESTROY(&(ct->ct_xdrs));
- if (ct->ct_addr.buf)
- diff --git a/libtirpc/src/rpc_soc.c b/libtirpc/src/rpc_soc.c
- index d7faf25..3073dac 100644
- --- a/libtirpc/src/rpc_soc.c
- +++ b/libtirpc/src/rpc_soc.c
- @@ -149,7 +149,7 @@ syserror:
- rpc_createerr.cf_error.re_errno = errno;
- err: if (madefd == TRUE)
- - (void)wintirpc_closesocket(fd);
- + (void)wintirpc_close(fd);
- (void) freenetconfigent(nconf);
- mutex_unlock(&rpcsoc_lock);
- return (NULL);
- @@ -298,7 +298,7 @@ svc_com_create(fd, sendsize, recvsize, netid)
- (void) freenetconfigent(nconf);
- if (svc == NULL) {
- if (madefd)
- - (void)wintirpc_closesocket(fd);
- + (void)wintirpc_close(fd);
- return (NULL);
- }
- port = (((struct sockaddr_in *)svc->xp_ltaddr.buf)->sin_port);
- @@ -551,7 +551,7 @@ clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz)
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
- if (*sockp != -1)
- - (void)wintirpc_closesocket(*sockp);
- + (void)wintirpc_close(*sockp);
- goto done;
- }
- }
- diff --git a/libtirpc/src/rpcb_clnt.c b/libtirpc/src/rpcb_clnt.c
- index 5fb5daa..03b7ef6 100644
- --- a/libtirpc/src/rpcb_clnt.c
- +++ b/libtirpc/src/rpcb_clnt.c
- @@ -458,7 +458,7 @@ local_rpcb()
- }
- /* Nobody needs this socket anymore; free the descriptor. */
- - wintirpc_closesocket(sock);
- + wintirpc_close(sock);
- try_nconf:
- @@ -493,7 +493,7 @@ try_nconf:
- */
- if (fd == SOCKET_ERROR)
- continue;
- - wintirpc_closesocket(fd);
- + wintirpc_close(fd);
- tmpnconf = nconf;
- if (!strcmp(nconf->nc_protofmly, NC_INET))
- hostname = IN4_LOCALHOST_STRING;
- @@ -683,11 +683,11 @@ __rpcbind_is_up()
- strncpy(sun.sun_path, _PATH_RPCBINDSOCK, sizeof(sun.sun_path));
- if (connect(_get_osfhandle(sock), (struct sockaddr *)&sun, sizeof(sun)) == SOCKET_ERROR) {
- - wintirpc_closesocket(sock);
- + wintirpc_close(sock);
- return (FALSE);
- }
- - wintirpc_closesocket(sock);
- + wintirpc_close(sock);
- return (TRUE);
- }
- diff --git a/libtirpc/src/rtime.c b/libtirpc/src/rtime.c
- index 1f3b8ab..2203b30 100644
- --- a/libtirpc/src/rtime.c
- +++ b/libtirpc/src/rtime.c
- @@ -150,6 +150,6 @@ do_close(s)
- int save;
- save = errno;
- - (void)wintirpc_closesocket(s);
- + (void)wintirpc_close(s);
- errno = save;
- }
- diff --git a/libtirpc/src/svc_dg.c b/libtirpc/src/svc_dg.c
- index b6bc541..2a49c5e 100644
- --- a/libtirpc/src/svc_dg.c
- +++ b/libtirpc/src/svc_dg.c
- @@ -257,7 +257,7 @@ svc_dg_destroy(xprt)
- xprt_unregister(xprt);
- if (xprt->xp_fd != -1)
- - (void)wintirpc_closesocket(xprt->xp_fd);
- + (void)wintirpc_close(xprt->xp_fd);
- XDR_DESTROY(&(su->su_xdrs));
- (void) mem_free(rpc_buffer(xprt), su->su_iosz);
- (void) mem_free(su, sizeof (*su));
- diff --git a/libtirpc/src/svc_generic.c b/libtirpc/src/svc_generic.c
- index 47a12a3..7ba0bfc 100644
- --- a/libtirpc/src/svc_generic.c
- +++ b/libtirpc/src/svc_generic.c
- @@ -291,7 +291,7 @@ svc_tli_create(fd, nconf, bindaddr, sendsz, recvsz)
- freedata:
- if (madefd)
- - (void)wintirpc_closesocket(fd);
- + (void)wintirpc_close(fd);
- if (xprt) {
- if (!madefd) /* so that svc_destroy doesnt close fd */
- xprt->xp_fd = RPC_ANYFD;
- diff --git a/libtirpc/src/svc_vc.c b/libtirpc/src/svc_vc.c
- index 5c57685..23ed338 100644
- --- a/libtirpc/src/svc_vc.c
- +++ b/libtirpc/src/svc_vc.c
- @@ -415,7 +415,7 @@ __svc_vc_dodestroy(xprt)
- cd = (struct cf_conn *)xprt->xp_p1;
- if (xprt->xp_fd != RPC_ANYFD)
- - (void)wintirpc_closesocket(xprt->xp_fd);
- + (void)wintirpc_close(xprt->xp_fd);
- if (xprt->xp_port != 0) {
- /* a rendezvouser socket */
- r = (struct cf_rendezvous *)xprt->xp_p1;
- diff --git a/libtirpc/src/wintirpc.c b/libtirpc/src/wintirpc.c
- index 243eb17..cc8266c 100644
- --- a/libtirpc/src/wintirpc.c
- +++ b/libtirpc/src/wintirpc.c
- @@ -186,6 +186,9 @@ void wintirpc_unregister_osfhandle(SOCKET handle)
- assert(handle != 0);
- assert(handle != SOCKET_ERROR);
- + if ((handle == 0) || (handle != SOCKET_ERROR))
- + return;
- +
- for (i=0 ; i < WINTIRPC_MAX_OSFHANDLE_FD_NHANDLE_VALUE ; i++) {
- if (handle_fd_map[i].m_s == handle) {
- handle_fd_map[i].m_s = SOCKET_ERROR;
- @@ -196,6 +199,24 @@ void wintirpc_unregister_osfhandle(SOCKET handle)
- (void)fprintf(stderr, "wintirpc_unregister_osfhandle: failed\n");
- }
- +void wintirpc_unregister_osf_fd(int fd)
- +{
- + int i;
- +
- + assert(fd >= 0);
- + if (fd < 0)
- + return;
- +
- + for (i=0 ; i < WINTIRPC_MAX_OSFHANDLE_FD_NHANDLE_VALUE ; i++) {
- + if (handle_fd_map[i].m_fd == fd) {
- + handle_fd_map[i].m_s = SOCKET_ERROR;
- + handle_fd_map[i].m_fd = -1;
- + return;
- + }
- + }
- + (void)fprintf(stderr, "wintirpc_unregister_osf_fd: failed\n");
- +}
- +
- int wintirpc_handle2fd(SOCKET handle)
- {
- int i;
- @@ -262,6 +283,13 @@ int wintirpc_closesocket(int in_fd)
- return closesocket(s);
- }
- +int wintirpc_close(int in_fd)
- +{
- + wintirpc_unregister_osf_fd(in_fd);
- +
- + return _close(in_fd);
- +}
- +
- int wintirpc_listen(int in_s, int backlog)
- {
- return listen(_get_osfhandle(in_s), backlog);
- diff --git a/libtirpc/tirpc/wintirpc.h b/libtirpc/tirpc/wintirpc.h
- index f5e5a9f..88027c6 100644
- --- a/libtirpc/tirpc/wintirpc.h
- +++ b/libtirpc/tirpc/wintirpc.h
- @@ -127,6 +127,7 @@ struct sockaddr_un {
- /* Prototypes */
- int wintirpc_socket(int af,int type, int protocol);
- 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_send(int s, const char *buf, int len, int flags);
- @@ -135,6 +136,7 @@ void wintirpc_syslog(int prio, const char *format, ...);
- void wintirpc_warnx(const char *format, ...);
- void wintirpc_register_osfhandle_fd(SOCKET handle, int fd);
- void wintirpc_unregister_osfhandle(SOCKET handle);
- +void wintirpc_unregister_osf_fd(int fd);
- int wintirpc_handle2fd(SOCKET handle);
- /* Debugging function */
- --
- 2.42.1
- From 786220e534a83b94c9bf2d312aaf7b5ad7a511d0 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Wed, 15 Nov 2023 13:33:02 +0100
- Subject: [PATCH 3/4] libtirpc: Fix Visual Studio 19 build warnings
- libtirpc: Fix Visual Studio 19 build warnings caused by missing
- casts. This also adds some |assert()| statments where the casts
- are not 100% safe.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- libtirpc/src/auth_sspi.c | 3 ++-
- libtirpc/src/rpc_generic.c | 6 +++++-
- libtirpc/src/rpcb_clnt.c | 2 +-
- libtirpc/src/svc_auth_unix.c | 2 +-
- libtirpc/src/svc_dg.c | 15 ++++++++++-----
- libtirpc/src/svc_vc.c | 2 ++
- libtirpc/src/xdr.c | 2 +-
- libtirpc/src/xdr_rec.c | 10 ++++++----
- 8 files changed, 28 insertions(+), 14 deletions(-)
- diff --git a/libtirpc/src/auth_sspi.c b/libtirpc/src/auth_sspi.c
- index 3bd558c..b5405c7 100644
- --- a/libtirpc/src/auth_sspi.c
- +++ b/libtirpc/src/auth_sspi.c
- @@ -869,7 +869,8 @@ void print_rpc_gss_sec(struct rpc_sspi_sec *ptr)
- }
- fprintf(fd_out, " qop: %d\n", ptr->qop);
- fprintf(fd_out, " service: %d\n", ptr->svc);
- - fprintf(fd_out, " cred: %p\n", ptr->cred);
- + fprintf(fd_out, " cred(%p) = { dwLower=%lld, dwUpper=%lld} \n",
- + &ptr->cred, ptr->cred.dwLower, ptr->cred.dwUpper);
- }
- void print_negotiated_attrs(PCtxtHandle ctx)
- diff --git a/libtirpc/src/rpc_generic.c b/libtirpc/src/rpc_generic.c
- index de8281a..5837020 100644
- --- a/libtirpc/src/rpc_generic.c
- +++ b/libtirpc/src/rpc_generic.c
- @@ -923,6 +923,10 @@ __rpc_sockisbound(int fd)
- struct netbuf *
- __rpc_set_netbuf(struct netbuf *nb, const void *ptr, size_t len)
- {
- + /* will it fit into netbuf ? */
- + if (len > INT_MAX)
- + return NULL;
- +
- if (nb->len != len) {
- if (nb->len)
- mem_free(nb->buf, nb->len);
- @@ -930,7 +934,7 @@ __rpc_set_netbuf(struct netbuf *nb, const void *ptr, size_t len)
- if (nb->buf == NULL)
- return NULL;
- - nb->maxlen = nb->len = len;
- + nb->maxlen = nb->len = (unsigned int)len;
- }
- memcpy(nb->buf, ptr, len);
- return nb;
- diff --git a/libtirpc/src/rpcb_clnt.c b/libtirpc/src/rpcb_clnt.c
- index 03b7ef6..906db37 100644
- --- a/libtirpc/src/rpcb_clnt.c
- +++ b/libtirpc/src/rpcb_clnt.c
- @@ -365,7 +365,7 @@ getclnthandle(host, nconf, targaddr)
- for (tres = res; tres != NULL; tres = tres->ai_next) {
- taddr.buf = tres->ai_addr;
- - taddr.len = taddr.maxlen = tres->ai_addrlen;
- + taddr.len = taddr.maxlen = (unsigned int)tres->ai_addrlen;
- #ifdef ND_DEBUG
- {
- diff --git a/libtirpc/src/svc_auth_unix.c b/libtirpc/src/svc_auth_unix.c
- index 551a252..b8e572e 100644
- --- a/libtirpc/src/svc_auth_unix.c
- +++ b/libtirpc/src/svc_auth_unix.c
- @@ -93,7 +93,7 @@ _svcauth_unix(rqst, msg)
- stat = AUTH_BADCRED;
- goto done;
- }
- - aup->aup_len = gid_len;
- + aup->aup_len = (u_int)gid_len;
- for (i = 0; i < gid_len; i++) {
- aup->aup_gids[i] = (int)IXDR_GET_INT32(buf);
- }
- diff --git a/libtirpc/src/svc_dg.c b/libtirpc/src/svc_dg.c
- index 2a49c5e..34bb7a8 100644
- --- a/libtirpc/src/svc_dg.c
- +++ b/libtirpc/src/svc_dg.c
- @@ -128,7 +128,8 @@ svc_dg_create(fd, sendsize, recvsize)
- su->su_iosz = ((MAX(sendsize, recvsize) + 3) / 4) * 4;
- if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL)
- goto freedata;
- - xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz,
- + assert(su->su_iosz < UINT_MAX);
- + xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), (u_int)su->su_iosz,
- XDR_DECODE);
- su->su_cache = NULL;
- xprt->xp_fd = fd;
- @@ -177,7 +178,8 @@ svc_dg_recv(xprt, msg)
- again:
- alen = sizeof (struct sockaddr_storage);
- - rlen = recvfrom(_get_osfhandle(xprt->xp_fd), rpc_buffer(xprt), su->su_iosz, 0,
- + assert(su->su_iosz < UINT_MAX);
- + rlen = recvfrom(_get_osfhandle(xprt->xp_fd), rpc_buffer(xprt), (u_int)su->su_iosz, 0,
- (struct sockaddr *)(void *)&ss, &alen);
- if (rlen == -1 && errno == EINTR)
- goto again;
- @@ -194,7 +196,8 @@ again:
- su->su_xid = msg->rm_xid;
- if (su->su_cache != NULL) {
- if (cache_get(xprt, msg, &reply, &replylen)) {
- - (void)wintirpc_sendto(xprt->xp_fd, reply, replylen, 0,
- + assert(replylen < INT_MAX);
- + (void)wintirpc_sendto(xprt->xp_fd, reply, (int)replylen, 0,
- (struct sockaddr *)(void *)&ss, alen);
- return (FALSE);
- }
- @@ -217,7 +220,8 @@ svc_dg_reply(xprt, msg)
- msg->rm_xid = su->su_xid;
- if (xdr_replymsg(xdrs, msg)) {
- slen = XDR_GETPOS(xdrs);
- - if (wintirpc_sendto(xprt->xp_fd, rpc_buffer(xprt), slen, 0,
- + assert(slen < INT_MAX);
- + if (wintirpc_sendto(xprt->xp_fd, rpc_buffer(xprt), (int)slen, 0,
- (struct sockaddr *)xprt->xp_rtaddr.buf,
- (socklen_t)xprt->xp_rtaddr.len) == (ssize_t) slen) {
- stat = TRUE;
- @@ -507,8 +511,9 @@ cache_set(xprt, replylen)
- victim->cache_replylen = replylen;
- victim->cache_reply = rpc_buffer(xprt);
- rpc_buffer(xprt) = newbuf;
- + assert(su->su_iosz < UINT_MAX);
- xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt),
- - su->su_iosz, XDR_ENCODE);
- + (u_int)su->su_iosz, XDR_ENCODE);
- victim->cache_xid = su->su_xid;
- victim->cache_proc = uc->uc_proc;
- victim->cache_vers = uc->uc_vers;
- diff --git a/libtirpc/src/svc_vc.c b/libtirpc/src/svc_vc.c
- index 23ed338..5fa8ee4 100644
- --- a/libtirpc/src/svc_vc.c
- +++ b/libtirpc/src/svc_vc.c
- @@ -314,7 +314,9 @@ rendezvous_request(xprt, msg)
- socklen_t len;
- struct __rpc_sockinfo si;
- SVCXPRT *newxprt;
- +#ifndef _WIN32 // CVE-2018-14621
- fd_set cleanfds;
- +#endif
- assert(xprt != NULL);
- assert(msg != NULL);
- diff --git a/libtirpc/src/xdr.c b/libtirpc/src/xdr.c
- index 38a959d..3c24314 100644
- --- a/libtirpc/src/xdr.c
- +++ b/libtirpc/src/xdr.c
- @@ -699,7 +699,7 @@ xdr_string(xdrs, cpp, maxsize)
- case XDR_ENCODE:
- if (sp == NULL)
- return FALSE;
- - size = strlen(sp);
- + size = (u_int)strlen(sp);
- break;
- case XDR_DECODE:
- break;
- diff --git a/libtirpc/src/xdr_rec.c b/libtirpc/src/xdr_rec.c
- index e4c512a..b5c9949 100644
- --- a/libtirpc/src/xdr_rec.c
- +++ b/libtirpc/src/xdr_rec.c
- @@ -320,13 +320,14 @@ xdrrec_getbytes(xdrs, addr, len)
- }
- static bool_t
- -xdrrec_putbytes(xdrs, addr, len)
- +xdrrec_putbytes(xdrs, addr, in_len)
- XDR *xdrs;
- const char *addr;
- - u_int len;
- + u_int in_len;
- {
- RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
- size_t current;
- + size_t len = in_len;
- while (len > 0) {
- current = (size_t)(PtrToUlong(rstrm->out_boundry) -
- @@ -729,12 +730,13 @@ fill_input_buf(rstrm)
- }
- static bool_t /* knows nothing about records! Only about input buffers */
- -get_input_bytes(rstrm, addr, len)
- +get_input_bytes(rstrm, addr, in_len)
- RECSTREAM *rstrm;
- char *addr;
- - u_int len;
- + u_int in_len;
- {
- size_t current;
- + size_t len = in_len;
- if (rstrm->nonblock) {
- if (len > (u_int)(rstrm->in_boundry - rstrm->in_finger))
- --
- 2.42.1
- From 4b465d8884acfa41977a1ce1075aabc5c15c1e37 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Wed, 15 Nov 2023 15:26:07 +0100
- Subject: [PATCH 4/4] daemon: "handle_mount: empty mount root" spam, should be
- debug message
- daemon: The warning "handle_mount: empty mount root" from
- daemon/mount.c is currently triggered very often, it should better be
- a debug message.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/mount.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/daemon/mount.c b/daemon/mount.c
- index a7b3a8c..a0cfd7d 100644
- --- a/daemon/mount.c
- +++ b/daemon/mount.c
- @@ -72,7 +72,7 @@ static int handle_mount(void *daemon_context, nfs41_upcall *upcall)
- EASSERT(args->hostport != NULL);
- if ((args->path == NULL) || (strlen(args->path) == 0)) {
- - eprintf("handle_mount: empty mount root\n");
- + dprintf(1, "handle_mount: empty mount root\n");
- status = ERROR_BAD_NETPATH;
- goto out;
- }
- --
- 2.42.1
msnfs41client: libtirpc+misc patches, 2023-11-15
Posted by Anonymous on Wed 15th Nov 2023 15:37
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.