xdrpp
RFC4506 XDR compiler and message library
rpc_msg.cc
1 
2 #include <iostream>
3 #include <xdrpp/exception.h>
4 
5 namespace xdr {
6 
7 using std::string;
8 
9 const char *
10 rpc_errmsg(accept_stat ev)
11 {
12  switch(ev) {
13  case SUCCESS:
14  return "RPC executed successfully";
15  case PROG_UNAVAIL:
16  return "remote hasn't exported program";
17  case PROG_MISMATCH:
18  return "remote can't support version #";
19  case PROC_UNAVAIL:
20  return "program can't support procedure";
21  case GARBAGE_ARGS:
22  return "procedure can't decode params";
23  case SYSTEM_ERR:
24  return "RPC system error";
25  default:
26  return "unknown accept_stat error";
27  }
28 }
29 
30 const char *
31 rpc_errmsg(auth_stat ev)
32 {
33  switch(ev) {
34  case AUTH_OK:
35  return "success";
36  case AUTH_BADCRED:
37  return "bad credential (seal broken)";
38  case AUTH_REJECTEDCRED:
39  return "client must begin new session";
40  case AUTH_BADVERF:
41  return "bad verifier (seal broken)";
42  case AUTH_REJECTEDVERF:
43  return "verifier expired or replayed";
44  case AUTH_TOOWEAK:
45  return "rejected for security reasons";
46  case AUTH_INVALIDRESP:
47  return "bogus response verifier";
48  case AUTH_FAILED:
49  return "reason unknown";
50  case AUTH_KERB_GENERIC:
51  return "kerberos generic error";
52  case AUTH_TIMEEXPIRE:
53  return "time of credential expired";
54  case AUTH_TKT_FILE:
55  return "problem with ticket file";
56  case AUTH_DECODE:
57  return "can't decode authenticator";
58  case AUTH_NET_ADDR:
59  return "wrong net address in ticket";
60  case RPCSEC_GSS_CREDPROBLEM:
61  return "no credentials for user";
62  case RPCSEC_GSS_CTXPROBLEM:
63  return "problem with context";
64  default:
65  return "auth_stat error";
66  }
67 }
68 
69 rpc_call_stat::rpc_call_stat(const rpc_msg &hdr)
70 {
71  if (hdr.body.mtype() == REPLY)
72  switch (hdr.body.rbody().stat()) {
73  case MSG_ACCEPTED:
74  type_ = ACCEPT_STAT;
75  accept_ = hdr.body.rbody().areply().reply_data.stat();
76  return;
77  case MSG_DENIED:
78  accept_ = SUCCESS;
79  switch (hdr.body.rbody().rreply().stat()) {
80  case RPC_MISMATCH:
81  type_ = RPCVERS_MISMATCH;
82  return;
83  case AUTH_ERROR:
84  type_ = AUTH_STAT;
85  auth_ = hdr.body.rbody().rreply().rj_why();
86  return;
87  }
88  }
89  type_ = GARBAGE_RES;
90 }
91 
92 const char *
93 rpc_call_stat::message() const
94 {
95  switch (type_) {
96  case ACCEPT_STAT:
97  return rpc_errmsg(accept_);
98  case AUTH_STAT:
99  return rpc_errmsg(auth_);
100  case RPCVERS_MISMATCH:
101  return "server reported rpcvers field with wrong value";
102  case GARBAGE_RES:
103  return "unable to unmarshal reply value sent by server";
104  case NETWORK_ERROR:
105  return "network error when communicating with server";
106  case BAD_ALLOC:
107  return "insufficient memory to unmarshal result";
108  default:
109  std::cerr << "rpc_call_stat: invalid type" << std::endl;
110  std::terminate();
111  }
112 }
113 
114 void
116 {
117  if (hdr.body.mtype() != REPLY)
118  throw xdr_runtime_error("call received when reply expected");
119  switch (hdr.body.rbody().stat()) {
120  case MSG_ACCEPTED:
121  if (hdr.body.rbody().areply().reply_data.stat() == SUCCESS)
122  return;
123  throw xdr_call_error(hdr.body.rbody().areply().reply_data.stat());
124  case MSG_DENIED:
125  if (hdr.body.rbody().rreply().stat() == AUTH_ERROR)
126  throw xdr_call_error(hdr.body.rbody().rreply().rj_why());
127  throw xdr_call_error(rpc_call_stat::RPCVERS_MISMATCH);
128  default:
129  throw xdr_runtime_error("check_call_hdr: garbage reply_stat");
130  }
131 }
132 
133 }
Most of the xdrpp library is encapsulated in the xdr namespace.
Definition: arpc.cc:4
Exceptions raised by RPC calls.
Generic class of XDR unmarshaling errors.
Definition: types.h:41
const char * rpc_errmsg(accept_stat ev)
Translate one of the conditions in RFC5531 for an unexecuted call into a string.
Definition: rpc_msg.cc:10
void check_call_hdr(const rpc_msg &hdr)
Check that an RPC header precedes a result.
Definition: rpc_msg.cc:115
This is the exception raised in an RPC client when it reaches the server and transmits a call...
Definition: exception.h:57