RPC -WR5441 Dokumentacja Strona 23

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 34
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 22
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
Przeglądanie stron 22
1 2 ... 18 19 20 21 22 23 24 25 26 27 28 ... 33 34

Komentarze do niniejszej Instrukcji

Brak uwag