1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*
* dispatch.c This file contains the function dispatch table.
*
* Authors: Donald J. Becker, <becker@super.org>
* Rick Sladkey, <jrs@world.std.com>
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
* Olaf Kirch, <okir@monad.swb.de>
*
* This software may be used for any purpose provided
* the above copyright notice is retained. It is supplied
* as is, with no warranty expressed or implied.
*/
#include "mountd.h"
#include "rpcmisc.h"
#include "haccess.h"
/*
* These are the global variables that hold all argument and result data.
*/
union argument_types argument;
union result_types result;
/*
* MOUNT versions supported by this implementation
*/
#define MAXVERS 2
/*
* This is a dispatch table to simplify error checking,
* and supply return attributes for NFS functions.
*/
#ifdef __STDC__
#define CONCAT(a,b) a##b
#define CONCAT3(a,b,c) a##b##c
#define CONCAT5(a,b,c,d,e) a##b##c##d##e
#define STRING(a) #a
#else
#define CONCAT(a,b) a/**/b
#define CONCAT3(a,b,c) a/**/b/**/c
#define CONCAT5(a,b,c,d,e) a/**/b/**/c/**/d/**/e
#define STRING(a) "a"
#endif
#define table_ent(vers, res_type, arg_type, funct) { \
sizeof(res_type), sizeof(arg_type), \
(xdrproc_t) CONCAT(xdr_,res_type), \
(xdrproc_t) CONCAT(xdr_,arg_type), \
(void *(*)()) CONCAT5(mountproc_,funct,_,vers,_svc), \
STRING(funct), CONCAT(pr_,arg_type) \
}
#define nil void
#define xdr_nil xdr_void
#define pr_nil pr_void
#define pr_char pr_void
struct dispatch_entry {
int res_size, arg_size; /* sizeof the res/arg structs */
xdrproc_t xdr_result;
xdrproc_t xdr_argument;
void *(*funct)(); /* function handler */
char *name; /* name of function */
char *(*log_print)(); /* ptr to debug handler */
};
static char * pr_void(void);
static char * pr_dirpath(dirpath *argp);
static struct dispatch_entry mount_1_table[] = {
table_ent(1,nil,nil,null), /* NULL */
table_ent(1,fhstatus,dirpath,mnt), /* MNT */
table_ent(1,mountlist,void,dump), /* DUMP */
table_ent(1,void,dirpath,umnt), /* UMNT */
table_ent(1,void,void,umntall), /* UMNTALL */
table_ent(1,exports,void,export), /* EXPORT */
table_ent(1,exports,void,exportall), /* EXPORTALL */
};
/* We cheat here and use version #1 for all except pathconf */
static struct dispatch_entry mount_2_table[] = {
table_ent(1,nil,nil,null), /* NULL */
table_ent(1,fhstatus,dirpath,mnt), /* MNT */
table_ent(1,mountlist,void,dump), /* DUMP */
table_ent(1,void,dirpath,umnt), /* UMNT */
table_ent(1,void,void,umntall), /* UMNTALL */
table_ent(1,exports,void,export), /* EXPORT */
table_ent(1,exports,void,exportall), /* EXPORTALL */
table_ent(2,ppathcnf,dirpath,pathconf), /* PATHCONF */
};
static struct dispatch_entry * dtable[MAXVERS] = {
mount_1_table,
mount_2_table,
};
static unsigned int dtnrprocs[MAXVERS] = {
sizeof(mount_1_table) / sizeof(mount_1_table[0]),
sizeof(mount_2_table) / sizeof(mount_2_table[0]),
};
/*
* The main dispatch routine.
*/
void
mount_dispatch(struct svc_req *rqstp, SVCXPRT *transp)
{
unsigned int proc_index, vers_index;
struct dispatch_entry *dtbl, *dent;
union result_types *resp;
struct sockaddr_in *sin;
sin = (struct sockaddr_in *) svc_getcaller(transp);
if (!client_checkaccess("rpc.mountd", sin, 0))
goto done;
proc_index = rqstp->rq_proc;
vers_index = rqstp->rq_vers - 1;
_rpcsvcdirty = 1;
if (vers_index >= MAXVERS) {
svcerr_progvers(transp, 1, MAXVERS);
goto done;
}
if (proc_index >= dtnrprocs[vers_index]) {
svcerr_noproc(transp);
goto done;
}
dtbl = dtable[vers_index];
dent = &dtbl[proc_index];
memset(&argument, 0, dent->arg_size);
if (!svc_getargs(transp, (xdrproc_t) dent->xdr_argument, &argument)) {
svcerr_decode(transp);
goto done;
}
/* Clear the result structure. */
memset(&result, 0, dent->res_size);
/* Log the call. */
if (logging_enabled(D_CALL))
log_call(rqstp, dent->name, dent->log_print(&argument));
/* Do the function call itself. */
resp = (*dent->funct) (&argument, rqstp);
if (!svc_sendreply(transp, dent->xdr_result, (caddr_t) resp)) {
svcerr_systemerr(transp);
}
if (!svc_freeargs(transp, (xdrproc_t) dent->xdr_argument, &argument)) {
Dprintf(L_ERROR, "unable to free RPC arguments, exiting\n");
exit(1);
}
done:
_rpcsvcdirty = 0;
if (need_reinit) {
reinitialize(0);
}
}
/*
* Functions for debugging output.
*/
static char *pr_void()
{
return ("");
}
static char *pr_dirpath(argp)
dirpath *argp;
{
return (*argp);
}
|