]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
nfs-utils: Provide type-checked version of svc_getcaller()
authorChuck Lever <chuck.lever@oracle.com>
Thu, 5 Mar 2009 11:20:40 +0000 (06:20 -0500)
committerSteve Dickson <steved@redhat.com>
Thu, 5 Mar 2009 11:20:40 +0000 (06:20 -0500)
TI-RPC's version of the svc_getcaller() macro points to a sockaddr_in6,
not a sockaddr_in, though for AF_INET callers, an AF_INET address
resides there.  To squelch compiler warnings when the TI-RPC version of
the svc_req structure is used, add inline helpers with appropriate
type casting.

Note that tcp_wrappers support only AF_INET addresses for now.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
support/include/rpcmisc.h
utils/mountd/mount_dispatch.c
utils/mountd/mountd.c
utils/statd/callback.c
utils/statd/monitor.c
utils/statd/simu.c
utils/statd/statd.c

index 5814a63a9ee17f772939b9d7d7c439d078d8f24f..f551a8577acf3850d2e5a7d88b89659f94fd76d4 100644 (file)
@@ -53,5 +53,14 @@ extern int   _rpcpmstart;
 extern int     _rpcfdtype;
 extern int     _rpcsvcdirty;
 
 extern int     _rpcfdtype;
 extern int     _rpcsvcdirty;
 
+static inline struct sockaddr_in *nfs_getrpccaller_in(SVCXPRT *xprt)
+{
+       return (struct sockaddr_in *)svc_getcaller(xprt);
+}
+
+static inline struct sockaddr *nfs_getrpccaller(SVCXPRT *xprt)
+{
+       return (struct sockaddr *)svc_getcaller(xprt);
+}
 
 #endif /* RPCMISC_H */
 
 #endif /* RPCMISC_H */
index f00c0c59316fe30454f1f3edb819e44b0748c46a..199fcece4f4682fb51e27dff87e42847b2096a47 100644 (file)
@@ -70,11 +70,12 @@ mount_dispatch(struct svc_req *rqstp, SVCXPRT *transp)
 {
        union mountd_arguments  argument;
        union mountd_results    result;
 {
        union mountd_arguments  argument;
        union mountd_results    result;
-
 #ifdef HAVE_TCP_WRAPPER
 #ifdef HAVE_TCP_WRAPPER
+       struct sockaddr_in *sin = nfs_getrpccaller_in(transp);
+
        /* remote host authorization check */
        /* remote host authorization check */
-       if (!check_default("mountd", svc_getcaller(transp),
-                          rqstp->rq_proc, MOUNTPROG)) {
+       if (sin->sin_family == AF_INET &&
+           !check_default("mountd", sin, rqstp->rq_proc, MOUNTPROG)) {
                svcerr_auth (transp, AUTH_FAILED);
                return;
        }
                svcerr_auth (transp, AUTH_FAILED);
                return;
        }
index deeaa07b6699d8af68fd8f4a128bf414f454fe89..8084359e290edd34faf489d56ff7a268b649d1f1 100644 (file)
@@ -202,8 +202,7 @@ mount_mnt_1_svc(struct svc_req *rqstp, dirpath *path, fhstatus *res)
 bool_t
 mount_dump_1_svc(struct svc_req *rqstp, void *argp, mountlist *res)
 {
 bool_t
 mount_dump_1_svc(struct svc_req *rqstp, void *argp, mountlist *res)
 {
-       struct sockaddr_in *addr =
-               (struct sockaddr_in *) svc_getcaller(rqstp->rq_xprt);
+       struct sockaddr_in *addr = nfs_getrpccaller_in(rqstp->rq_xprt);
 
        xlog(D_CALL, "dump request from %s.", inet_ntoa(addr->sin_addr));
        *res = mountlist_list();
 
        xlog(D_CALL, "dump request from %s.", inet_ntoa(addr->sin_addr));
        *res = mountlist_list();
@@ -214,8 +213,7 @@ mount_dump_1_svc(struct svc_req *rqstp, void *argp, mountlist *res)
 bool_t
 mount_umnt_1_svc(struct svc_req *rqstp, dirpath *argp, void *resp)
 {
 bool_t
 mount_umnt_1_svc(struct svc_req *rqstp, dirpath *argp, void *resp)
 {
-       struct sockaddr_in *sin
-               = (struct sockaddr_in *) svc_getcaller(rqstp->rq_xprt);
+       struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
        nfs_export      *exp;
        char            *p = *argp;
        char            rpath[MAXPATHLEN+1];
        nfs_export      *exp;
        char            *p = *argp;
        char            rpath[MAXPATHLEN+1];
@@ -242,15 +240,14 @@ mount_umntall_1_svc(struct svc_req *rqstp, void *argp, void *resp)
        /* Reload /etc/xtab if necessary */
        auth_reload();
 
        /* Reload /etc/xtab if necessary */
        auth_reload();
 
-       mountlist_del_all((struct sockaddr_in *) svc_getcaller(rqstp->rq_xprt));
+       mountlist_del_all(nfs_getrpccaller_in(rqstp->rq_xprt));
        return 1;
 }
 
 bool_t
 mount_export_1_svc(struct svc_req *rqstp, void *argp, exports *resp)
 {
        return 1;
 }
 
 bool_t
 mount_export_1_svc(struct svc_req *rqstp, void *argp, exports *resp)
 {
-       struct sockaddr_in *addr =
-               (struct sockaddr_in *) svc_getcaller(rqstp->rq_xprt);
+       struct sockaddr_in *addr = nfs_getrpccaller_in(rqstp->rq_xprt);
 
        xlog(D_CALL, "export request from %s.", inet_ntoa(addr->sin_addr));
        *resp = get_exportlist();
 
        xlog(D_CALL, "export request from %s.", inet_ntoa(addr->sin_addr));
        *resp = get_exportlist();
@@ -261,8 +258,7 @@ mount_export_1_svc(struct svc_req *rqstp, void *argp, exports *resp)
 bool_t
 mount_exportall_1_svc(struct svc_req *rqstp, void *argp, exports *resp)
 {
 bool_t
 mount_exportall_1_svc(struct svc_req *rqstp, void *argp, exports *resp)
 {
-       struct sockaddr_in *addr =
-               (struct sockaddr_in *) svc_getcaller(rqstp->rq_xprt);
+       struct sockaddr_in *addr = nfs_getrpccaller_in(rqstp->rq_xprt);
 
        xlog(D_CALL, "exportall request from %s.", inet_ntoa(addr->sin_addr));
        *resp = get_exportlist();
 
        xlog(D_CALL, "exportall request from %s.", inet_ntoa(addr->sin_addr));
        *resp = get_exportlist();
@@ -284,8 +280,7 @@ mount_exportall_1_svc(struct svc_req *rqstp, void *argp, exports *resp)
 bool_t
 mount_pathconf_2_svc(struct svc_req *rqstp, dirpath *path, ppathcnf *res)
 {
 bool_t
 mount_pathconf_2_svc(struct svc_req *rqstp, dirpath *path, ppathcnf *res)
 {
-       struct sockaddr_in *sin
-               = (struct sockaddr_in *) svc_getcaller(rqstp->rq_xprt);
+       struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
        struct stat     stb;
        nfs_export      *exp;
        char            rpath[MAXPATHLEN+1];
        struct stat     stb;
        nfs_export      *exp;
        char            rpath[MAXPATHLEN+1];
@@ -383,8 +378,7 @@ static struct nfs_fh_len *
 get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret,
                mountstat3 *error, int v3)
 {
 get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret,
                mountstat3 *error, int v3)
 {
-       struct sockaddr_in *sin =
-               (struct sockaddr_in *) svc_getcaller(rqstp->rq_xprt);
+       struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
        struct stat     stb, estb;
        nfs_export      *exp;
        struct nfs_fh_len *fh;
        struct stat     stb, estb;
        nfs_export      *exp;
        struct nfs_fh_len *fh;
index 505fdb3c742112d09ea25230ee5588c4ff6e9915..888523872931055c70e6bbac39d1778a4c31d1fd 100644 (file)
@@ -9,10 +9,13 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+
+#include <arpa/inet.h>
+
+#include "rpcmisc.h"
 #include "misc.h"
 #include "statd.h"
 #include "notlist.h"
 #include "misc.h"
 #include "statd.h"
 #include "notlist.h"
-#include <arpa/inet.h>
 
 /* Callback notify list. */
 /* notify_list *cbnl = NULL; ... never used */
 
 /* Callback notify list. */
 /* notify_list *cbnl = NULL; ... never used */
@@ -29,8 +32,8 @@ sm_notify_1_svc(struct stat_chge *argp, struct svc_req *rqstp)
 {
        notify_list    *lp, *call;
        static char    *result = NULL;
 {
        notify_list    *lp, *call;
        static char    *result = NULL;
-       char *ip_addr = xstrdup(inet_ntoa(svc_getcaller(rqstp->rq_xprt)
-                                         ->sin_addr));
+       struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
+       char *ip_addr = xstrdup(inet_ntoa(sin->sin_addr));
 
        dprintf(N_DEBUG, "Received SM_NOTIFY from %s, state: %d",
                                argp->mon_name, argp->state);
 
        dprintf(N_DEBUG, "Received SM_NOTIFY from %s, state: %d",
                                argp->mon_name, argp->state);
index 24c2531f4cdf3cc31802c1aec67a226d2e20f19c..169cd78ac82b17a99c5ce90850bb97f4d4fac901 100644 (file)
@@ -20,6 +20,8 @@
 #include <errno.h>
 #include <arpa/inet.h>
 #include <dirent.h>
 #include <errno.h>
 #include <arpa/inet.h>
 #include <dirent.h>
+
+#include "rpcmisc.h"
 #include "misc.h"
 #include "statd.h"
 #include "notlist.h"
 #include "misc.h"
 #include "statd.h"
 #include "notlist.h"
@@ -36,9 +38,10 @@ notify_list *                rtnl = NULL;    /* Run-time notify list. */
 static int
 caller_is_localhost(struct svc_req *rqstp)
 {
 static int
 caller_is_localhost(struct svc_req *rqstp)
 {
+       struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
        struct in_addr  caller;
 
        struct in_addr  caller;
 
-       caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
+       caller = sin->sin_addr;
        if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
                note(N_WARNING,
                        "Call to statd from non-local host %s",
        if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
                note(N_WARNING,
                        "Call to statd from non-local host %s",
index 25e8badad160246f2efb600a51659deed8fb4d9e..a7ecb85c275509e687c4351955c4c5b4d1e3c03d 100644 (file)
@@ -7,8 +7,10 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+
 #include <arpa/inet.h>
 
 #include <arpa/inet.h>
 
+#include "rpcmisc.h"
 #include "statd.h"
 #include "notlist.h"
 
 #include "statd.h"
 #include "notlist.h"
 
@@ -21,17 +23,23 @@ extern void my_svc_exit (void);
 void *
 sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
 {
 void *
 sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
 {
+  struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
   static char *result = NULL;
   struct in_addr caller;
 
   static char *result = NULL;
   struct in_addr caller;
 
-  caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
+  if (sin->sin_family != AF_INET) {
+    note(N_WARNING, "Call to statd from non-AF_INET address");
+    goto failure;
+  }
+
+  caller = sin->sin_addr;
   if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
     note(N_WARNING, "Call to statd from non-local host %s",
       inet_ntoa(caller));
     goto failure;
   }
 
   if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
     note(N_WARNING, "Call to statd from non-local host %s",
       inet_ntoa(caller));
     goto failure;
   }
 
-  if (ntohs(svc_getcaller(rqstp->rq_xprt)->sin_port) >= 1024) {
+  if (ntohs(sin->sin_port) >= 1024) {
     note(N_WARNING, "Call to statd-simu-crash from unprivileged port");
     goto failure;
   }
     note(N_WARNING, "Call to statd-simu-crash from unprivileged port");
     goto failure;
   }
index 321f7a945a81533da91ff8e1a8bc7b317c1e349f..6da2ab283d145284d2f919e7c3ec3faf35933463 100644 (file)
@@ -88,9 +88,11 @@ extern void simulator (int, char **);
 static void 
 sm_prog_1_wrapper (struct svc_req *rqstp, register SVCXPRT *transp)
 {
 static void 
 sm_prog_1_wrapper (struct svc_req *rqstp, register SVCXPRT *transp)
 {
+       struct sockaddr_in *sin = nfs_getrpccaller_in(transp);
+
        /* remote host authorization check */
        /* remote host authorization check */
-       if (!check_default("statd", svc_getcaller(transp),
-                                rqstp->rq_proc, SM_PROG)) {
+       if (sin->sin_family == AF_INET &&
+           !check_default("statd", sin, rqstp->rq_proc, SM_PROG)) {
                svcerr_auth (transp, AUTH_FAILED);
                return;
        }
                svcerr_auth (transp, AUTH_FAILED);
                return;
        }