Specifications
Remote Procedure Call Programming Guide Page 23
nuser(rqstp, transp)
struct svc_req *rqstp;
SVCXPRT *transp;
{
struct authunix_parms *unix_cred;
int uid;
unsigned long nusers;
/*
* we don’t care about authentication for null proc
*/
if (rqstp->rq_proc == NULLPROC) {
if (!svc_sendreply(transp, xdr_void, 0)) {
fprintf(stderr, "can’t reply to RPC call\n");
return (1);
}
return;
}
/*
* now get the uid
*/
switch (rqstp->rq_cred.oa_flavor) {
case AUTH_UNIX:
unix_cred =
(struct authunix_parms *)rqstp->rq_clntcred;
uid = unix_cred->aup_uid;
break;
case AUTH_NULL:
default:
svcerr_weakauth(transp);
return;
}
switch (rqstp->rq_proc) {
case RUSERSPROC_NUM:
/*
* make sure caller is allowed to call this proc
*/
if (uid == 16) {
svcerr_systemerr(transp);
return;
}
/*
* Code here to compute the number of users
* and assign it to the variable nusers
*/
if (!svc_sendreply(transp, xdr_u_long, &nusers)) {
fprintf(stderr, "can’t reply to RPC call\n");
return (1);
}
return;
default:
svcerr_noproc(transp);
return;
}
}
A few things should be noted here. First, it is customary not to check the authentication parameters associ-
ated with the NULLPROC (procedure number zero). Second, if the authentication parameter’s type is not
suitable for your service, you should call svcerr_weakauth(). And finally, the service protocol itself should
return status for access denied; in the case of our example, the protocol does not have such a status, so we