summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rpc/rpc-lib/src/auth-glusterfs.c6
-rw-r--r--rpc/rpc-lib/src/auth-unix.c1
-rw-r--r--rpc/rpc-lib/src/rpc-clnt.c146
-rw-r--r--rpc/rpc-lib/src/rpc-common.c6
-rw-r--r--rpc/rpc-lib/src/rpc-transport.c205
-rw-r--r--rpc/rpc-lib/src/rpcsvc-auth.c98
-rw-r--r--rpc/rpc-lib/src/rpcsvc.c630
-rw-r--r--rpc/rpc-lib/src/xdr-rpc.c78
-rw-r--r--rpc/rpc-lib/src/xdr-rpcclnt.c31
9 files changed, 247 insertions, 954 deletions
diff --git a/rpc/rpc-lib/src/auth-glusterfs.c b/rpc/rpc-lib/src/auth-glusterfs.c
index 9a9021046cf..bfa572b4ffb 100644
--- a/rpc/rpc-lib/src/auth-glusterfs.c
+++ b/rpc/rpc-lib/src/auth-glusterfs.c
@@ -130,6 +130,8 @@ xdr_to_glusterfs_auth (char *buf, struct auth_glusterfs_parms *req)
xdrmem_create (&xdr, buf, sizeof (struct auth_glusterfs_parms),
XDR_DECODE);
if (!xdr_auth_glusterfs_parms (&xdr, req)) {
+ gf_log ("", GF_LOG_WARNING,
+ "failed to decode glusterfs parameters");
ret = -1;
goto ret;
}
@@ -162,6 +164,8 @@ int auth_glusterfs_authenticate (rpcsvc_request_t *req, void *priv)
ret = xdr_to_glusterfs_auth (req->cred.authdata, &au);
if (ret == -1) {
+ gf_log ("", GF_LOG_WARNING,
+ "failed to decode glusterfs credentials");
ret = RPCSVC_AUTH_REJECT;
goto err;
}
@@ -173,6 +177,8 @@ int auth_glusterfs_authenticate (rpcsvc_request_t *req, void *priv)
req->auxgidcount = au.ngrps;
if (req->auxgidcount > 16) {
+ gf_log ("", GF_LOG_WARNING,
+ "more than 16 aux gids found, failing authentication");
ret = RPCSVC_AUTH_REJECT;
goto err;
}
diff --git a/rpc/rpc-lib/src/auth-unix.c b/rpc/rpc-lib/src/auth-unix.c
index 30b395bd4fa..d3afbad6342 100644
--- a/rpc/rpc-lib/src/auth-unix.c
+++ b/rpc/rpc-lib/src/auth-unix.c
@@ -54,6 +54,7 @@ int auth_unix_authenticate (rpcsvc_request_t *req, void *priv)
ret = xdr_to_auth_unix_cred (req->cred.authdata, req->cred.datalen,
&aup, machname, req->auxgids);
if (ret == -1) {
+ gf_log ("", GF_LOG_WARNING, "failed to decode unix credentials");
ret = RPCSVC_AUTH_REJECT;
goto err;
}
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c
index 99bba8cb407..7e8a67a8137 100644
--- a/rpc/rpc-lib/src/rpc-clnt.c
+++ b/rpc/rpc-lib/src/rpc-clnt.c
@@ -78,7 +78,6 @@ __saved_frames_put (struct saved_frames *frames, void *frame,
saved_frame = mem_get (rpcreq->conn->rpc_clnt->saved_frames_pool);
if (!saved_frame) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
goto out;
}
/* THIS should be saved and set back */
@@ -103,9 +102,8 @@ void
saved_frames_delete (struct saved_frame *saved_frame,
rpc_clnt_connection_t *conn)
{
- if (!saved_frame || !conn) {
- goto out;
- }
+ GF_VALIDATE_OR_GOTO ("rpc-clnt", saved_frame, out);
+ GF_VALIDATE_OR_GOTO ("rpc-clnt", conn, out);
pthread_mutex_lock (&conn->lock);
{
@@ -164,7 +162,7 @@ call_bail (void *data)
(void *) clnt);
if (conn->timer == NULL) {
- gf_log (conn->trans->name, GF_LOG_DEBUG,
+ gf_log (conn->trans->name, GF_LOG_WARNING,
"Cannot create bailout timer");
}
}
@@ -250,7 +248,6 @@ saved_frames_new (void)
saved_frames = GF_CALLOC (1, sizeof (*saved_frames),
gf_common_mt_rpcclnt_savedframe_t);
if (!saved_frames) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
return NULL;
}
@@ -330,13 +327,14 @@ saved_frames_unwind (struct saved_frames *saved_frames)
if (!trav->rpcreq || !trav->rpcreq->prog)
continue;
- gf_log_callingfn ("rpc-clnt", GF_LOG_ERROR,
+ gf_log_callingfn (trav->rpcreq->conn->trans->name,
+ GF_LOG_ERROR,
"forced unwinding frame type(%s) op(%s(%d)) "
"called at %s",
trav->rpcreq->prog->progname,
- (trav->rpcreq->prog->procnames) ?
- trav->rpcreq->prog->procnames[trav->rpcreq->procnum]
- : "--",
+ ((trav->rpcreq->prog->procnames) ?
+ trav->rpcreq->prog->procnames[trav->rpcreq->procnum]
+ : "--"),
trav->rpcreq->procnum, timestr);
saved_frames->count--;
@@ -429,10 +427,8 @@ rpc_clnt_fill_request_info (struct rpc_clnt *clnt, rpc_request_info_t *info)
pthread_mutex_unlock (&clnt->conn.lock);
if (ret == -1) {
- gf_log ("rpc-clnt", GF_LOG_CRITICAL, "cannot lookup the saved "
- "frame corresponding to xid (%d) for msg arrived on "
- "transport %s",
- info->xid, clnt->conn.trans->name);
+ gf_log (clnt->conn.trans->name, GF_LOG_CRITICAL, "cannot lookup the saved "
+ "frame corresponding to xid (%d)", info->xid);
goto out;
}
@@ -490,7 +486,7 @@ rpc_clnt_connection_cleanup (rpc_clnt_connection_t *conn)
clnt = conn->rpc_clnt;
- gf_log ("rpc-clnt", GF_LOG_DEBUG,
+ gf_log (conn->trans->name, GF_LOG_TRACE,
"cleaning up state in transport object %p", conn->trans);
pthread_mutex_lock (&conn->lock);
@@ -618,7 +614,8 @@ rpc_clnt_reply_init (rpc_clnt_connection_t *conn, rpc_transport_pollin_t *msg,
ret = xdr_to_rpc_reply (msgbuf, msglen, &rpcmsg, &progmsg,
req->verf.authdata);
if (ret != 0) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "RPC reply decoding failed");
+ gf_log (conn->trans->name, GF_LOG_WARNING,
+ "RPC reply decoding failed");
goto out;
}
@@ -628,34 +625,13 @@ rpc_clnt_reply_init (rpc_clnt_connection_t *conn, rpc_transport_pollin_t *msg,
goto out;
}
- gf_log ("rpc-clnt", GF_LOG_TRACE, "recieved rpc message (RPC XID: 0x%ux"
+ gf_log (conn->trans->name, GF_LOG_TRACE, "recieved rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)",
saved_frame->rpcreq->xid,
saved_frame->rpcreq->prog->progname,
saved_frame->rpcreq->prog->progver,
saved_frame->rpcreq->procnum, conn->trans->name);
-/* TODO: */
- /* TODO: AUTH */
- /* The verifier that is sent in a reply is a string that can be used as
- * a shorthand in credentials for future transactions. We can opt not to
- * use this shorthand, preffering to use the original AUTH_UNIX method
- * for authentication (containing all the details for authentication in
- * credential itself). Hence it is not mandatory for us to be checking
- * the verifier. See Appendix A of rfc-5531 for more details.
- */
- /*
- * ret = rpc_authenticate (req);
- * if (ret == RPC_AUTH_REJECT) {
- * gf_log ("rpc-clnt", GF_LOG_ERROR, "Failed authentication");
- * ret = -1;
- * goto out;
- * }
- */
-
- /* If the error is not RPC_MISMATCH, we consider the call as accepted
- * since we are not handling authentication failures for now.
- */
req->rpc_status = 0;
out:
@@ -684,11 +660,13 @@ rpc_clnt_handle_cbk (struct rpc_clnt *clnt, rpc_transport_pollin_t *msg)
clnt = rpc_clnt_ref (clnt);
ret = xdr_to_rpc_call (msgbuf, msglen, &rpcmsg, &progmsg, NULL,NULL);
if (ret == -1) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "RPC call decoding failed");
+ gf_log (clnt->conn.trans->name, GF_LOG_WARNING,
+ "RPC call decoding failed");
goto out;
}
- gf_log ("rpc-clnt", GF_LOG_INFO, "recieved rpc message (XID: 0x%lx, "
+ gf_log (clnt->conn.trans->name, GF_LOG_TRACE,
+ "recieved rpc message (XID: 0x%lx, "
"Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "
"from rpc-transport (%s)", rpc_call_xid (&rpcmsg),
rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg),
@@ -735,23 +713,24 @@ rpc_clnt_handle_reply (struct rpc_clnt *clnt, rpc_transport_pollin_t *pollin)
xid = ntoh32 (*((uint32_t *)pollin->vector[0].iov_base));
saved_frame = lookup_frame (conn, xid);
if (saved_frame == NULL) {
- gf_log ("rpc-clnt", GF_LOG_CRITICAL, "cannot lookup the "
- "saved frame for reply with xid (%d)", xid);
+ gf_log (conn->trans->name, GF_LOG_ERROR,
+ "cannot lookup the saved frame for reply with xid (%u)",
+ xid);
goto out;
}
req = saved_frame->rpcreq;
if (req == NULL) {
- gf_log ("rpc-clnt", GF_LOG_CRITICAL,
- "saved_frame for reply with xid (%d)", xid);
+ gf_log (conn->trans->name, GF_LOG_ERROR,
+ "no request with frame for xid (%u)", xid);
goto out;
}
ret = rpc_clnt_reply_init (conn, pollin, req, saved_frame);
if (ret != 0) {
req->rpc_status = -1;
- gf_log ("rpc-clnt", GF_LOG_DEBUG, "initialising rpc reply "
- "failed");
+ gf_log (conn->trans->name, GF_LOG_WARNING,
+ "initialising rpc reply failed");
}
req->cbkfn (req, req->rsp, req->rspcnt, saved_frame->frame);
@@ -928,7 +907,7 @@ rpc_clnt_connection_init (struct rpc_clnt *clnt, glusterfs_ctx_t *ctx,
ret = dict_get_int32 (options, "frame-timeout",
&conn->frame_timeout);
if (ret >= 0) {
- gf_log (name, GF_LOG_DEBUG,
+ gf_log (name, GF_LOG_INFO,
"setting frame-timeout to %d", conn->frame_timeout);
} else {
gf_log (name, GF_LOG_DEBUG,
@@ -938,7 +917,7 @@ rpc_clnt_connection_init (struct rpc_clnt *clnt, glusterfs_ctx_t *ctx,
conn->trans = rpc_transport_load (ctx, options, name);
if (!conn->trans) {
- gf_log ("rpc-clnt", GF_LOG_DEBUG, "loading of new rpc-transport"
+ gf_log (name, GF_LOG_WARNING, "loading of new rpc-transport"
" failed");
goto out;
}
@@ -950,7 +929,7 @@ rpc_clnt_connection_init (struct rpc_clnt *clnt, glusterfs_ctx_t *ctx,
ret = rpc_transport_register_notify (conn->trans, rpc_clnt_notify,
conn);
if (ret == -1) {
- gf_log ("rpc-clnt", GF_LOG_DEBUG, "registering notify failed");
+ gf_log (name, GF_LOG_WARNING, "registering notify failed");
rpc_clnt_connection_cleanup (conn);
conn = NULL;
goto out;
@@ -958,7 +937,7 @@ rpc_clnt_connection_init (struct rpc_clnt *clnt, glusterfs_ctx_t *ctx,
conn->saved_frames = saved_frames_new ();
if (!conn->saved_frames) {
- gf_log ("rpc-clnt", GF_LOG_DEBUG, "creation of saved_frames "
+ gf_log (name, GF_LOG_WARNING, "creation of saved_frames "
"failed");
rpc_clnt_connection_cleanup (conn);
goto out;
@@ -979,7 +958,6 @@ rpc_clnt_new (dict_t *options,
rpc = GF_CALLOC (1, sizeof (*rpc), gf_common_mt_rpcclnt_t);
if (!rpc) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
goto out;
}
@@ -1064,6 +1042,7 @@ xdr_serialize_glusterfs_auth (char *dest, struct auth_glusterfs_parms *au)
XDR_ENCODE);
if (!xdr_auth_glusterfs_parms (&xdr, au)) {
+ gf_log ("", GF_LOG_WARNING, "failed to encode auth glusterfs elements");
ret = -1;
goto ret;
}
@@ -1176,7 +1155,6 @@ rpc_clnt_record_build_record (struct rpc_clnt *clnt, int prognum, int progver,
*/
request_iob = iobuf_get (clnt->ctx->iobuf_pool);
if (!request_iob) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "Failed to get iobuf");
goto out;
}
@@ -1188,8 +1166,8 @@ rpc_clnt_record_build_record (struct rpc_clnt *clnt, int prognum, int progver,
ret = rpc_clnt_fill_request (prognum, progver, procnum, payload, xid,
au, &request, auth_data);
if (ret == -1) {
- gf_log ("rpc-clnt", GF_LOG_DEBUG, "cannot build a rpc-request "
- "xid (%"PRIu64")", xid);
+ gf_log (clnt->conn.trans->name, GF_LOG_WARNING,
+ "cannot build a rpc-request xid (%"PRIu64")", xid);
goto out;
}
@@ -1199,8 +1177,8 @@ rpc_clnt_record_build_record (struct rpc_clnt *clnt, int prognum, int progver,
//GF_FREE (request.rm_call.cb_cred.oa_base);
if (!recordhdr.iov_base) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "Failed to build record "
- " header");
+ gf_log (clnt->conn.trans->name, GF_LOG_ERROR,
+ "Failed to build record header");
iobuf_unref (request_iob);
request_iob = NULL;
recbuf->iov_base = NULL;
@@ -1235,7 +1213,7 @@ rpc_clnt_record (struct rpc_clnt *clnt, call_frame_t *call_frame,
if (!au.lk_owner)
au.lk_owner = au.pid;
- gf_log ("", GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d"
+ gf_log (clnt->conn.trans->name, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d"
", gid: %d, owner: %"PRId64,
au.pid, au.uid, au.gid, au.lk_owner);
@@ -1253,7 +1231,8 @@ rpc_clnt_record (struct rpc_clnt *clnt, call_frame_t *call_frame,
callid, &au,
rpchdr);
if (!request_iob) {
- gf_log ("rpc-clnt", GF_LOG_DEBUG, "cannot build rpc-record");
+ gf_log (clnt->conn.trans->name, GF_LOG_WARNING,
+ "cannot build rpc-record");
goto out;
}
@@ -1288,7 +1267,8 @@ rpcclnt_cbk_program_register (struct rpc_clnt *clnt,
pthread_mutex_unlock (&clnt->lock);
if (already_registered) {
- gf_log ("rpc-clnt", GF_LOG_DEBUG, "already registered");
+ gf_log_callingfn (clnt->conn.trans->name, GF_LOG_DEBUG,
+ "already registered");
ret = 0;
goto out;
}
@@ -1296,7 +1276,6 @@ rpcclnt_cbk_program_register (struct rpc_clnt *clnt,
tmp = GF_CALLOC (1, sizeof (*tmp),
gf_common_mt_rpcclnt_cb_program_t);
if (tmp == NULL) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
goto out;
}
@@ -1310,13 +1289,15 @@ rpcclnt_cbk_program_register (struct rpc_clnt *clnt,
pthread_mutex_unlock (&clnt->lock);
ret = 0;
- gf_log ("rpc-clnt", GF_LOG_DEBUG, "New program registered: %s, Num: %d,"
- " Ver: %d", program->progname, program->prognum,
+ gf_log (clnt->conn.trans->name, GF_LOG_DEBUG,
+ "New program registered: %s, Num: %d, Ver: %d",
+ program->progname, program->prognum,
program->progver);
out:
if (ret == -1) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "Program registration failed:"
+ gf_log (clnt->conn.trans->name, GF_LOG_ERROR,
+ "Program registration failed:"
" %s, Num: %d, Ver: %d", program->progname,
program->prognum, program->progver);
}
@@ -1350,7 +1331,6 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog,
rpcreq = mem_get (rpc->reqpool);
if (rpcreq == NULL) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
goto out;
}
@@ -1360,7 +1340,6 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog,
if (!iobref) {
iobref = iobref_new ();
if (!iobref) {
- gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
goto out;
}
@@ -1399,7 +1378,7 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog,
procnum, proglen,
&rpchdr, callid);
if (!request_iob) {
- gf_log ("rpc-clnt", GF_LOG_DEBUG,
+ gf_log (conn->trans->name, GF_LOG_WARNING,
"cannot build rpc-record");
goto unlock;
}
@@ -1424,8 +1403,8 @@ rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog,
ret = rpc_transport_submit_request (rpc->conn.trans,
&req);
if (ret == -1) {
- gf_log ("rpc-clnt", GF_LOG_TRACE, "failed to "
- "submit rpc-request "
+ gf_log (conn->trans->name, GF_LOG_WARNING,
+ "failed to submit rpc-request "
"(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid,
rpcreq->prog->progname, rpcreq->prog->progver,
@@ -1535,15 +1514,40 @@ rpc_clnt_unref (struct rpc_clnt *rpc)
void
rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config)
{
- if (config->rpc_timeout)
+ if (config->rpc_timeout) {
+ if (config->rpc_timeout != rpc->conn.config.rpc_timeout)
+ gf_log (rpc->conn.trans->name, GF_LOG_INFO,
+ "changing timeout to %d (from %d)",
+ config->rpc_timeout,
+ rpc->conn.config.rpc_timeout);
rpc->conn.config.rpc_timeout = config->rpc_timeout;
+ }
+
+ if (config->remote_port) {
+ if (config->remote_port != rpc->conn.config.remote_port)
+ gf_log (rpc->conn.trans->name, GF_LOG_INFO,
+ "changing port to %d (from %d)",
+ config->remote_port,
+ rpc->conn.config.remote_port);
- if (config->remote_port)
rpc->conn.config.remote_port = config->remote_port;
+ }
if (config->remote_host) {
- if (rpc->conn.config.remote_host)
+ if (rpc->conn.config.remote_host) {
+ if (strcmp (rpc->conn.config.remote_host,
+ config->remote_host))
+ gf_log (rpc->conn.trans->name, GF_LOG_INFO,
+ "changing port to %s (from %s)",
+ config->remote_host,
+ rpc->conn.config.remote_host);
FREE (rpc->conn.config.remote_host);
+ } else {
+ gf_log (rpc->conn.trans->name, GF_LOG_INFO,
+ "setting hostname to %s",
+ config->remote_host);
+ }
+
rpc->conn.config.remote_host = gf_strdup (config->remote_host);
}
}
diff --git a/rpc/rpc-lib/src/rpc-common.c b/rpc/rpc-lib/src/rpc-common.c
index 941f01a2510..db7b92834e7 100644
--- a/rpc/rpc-lib/src/rpc-common.c
+++ b/rpc/rpc-lib/src/rpc-common.c
@@ -18,7 +18,7 @@
*/
-
+#include "logging.h"
#include "xdr-common.h"
ssize_t
@@ -34,6 +34,8 @@ xdr_serialize_generic (struct iovec outmsg, void *res, xdrproc_t proc)
XDR_ENCODE);
if (!proc (&xdr, res)) {
+ gf_log_callingfn ("xdr", GF_LOG_WARNING,
+ "XDR encoding failed");
ret = -1;
goto ret;
}
@@ -58,6 +60,8 @@ xdr_to_generic (struct iovec inmsg, void *args, xdrproc_t proc)
XDR_DECODE);
if (!proc (&xdr, args)) {
+ gf_log_callingfn ("xdr", GF_LOG_WARNING,
+ "XDR decoding failed");
ret = -1;
goto ret;
}
diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c
index 10c835cc8eb..e8b56678bd9 100644
--- a/rpc/rpc-lib/src/rpc-transport.c
+++ b/rpc/rpc-lib/src/rpc-transport.c
@@ -467,44 +467,53 @@ int32_t
rpc_transport_get_myaddr (rpc_transport_t *this, char *peeraddr, int addrlen,
struct sockaddr_storage *sa, size_t salen)
{
- if (!this)
- return -1;
+ int32_t ret = -1;
+ GF_VALIDATE_OR_GOTO ("rpc", this, out);
+
+ ret = this->ops->get_myaddr (this, peeraddr, addrlen, sa, salen);
- return this->ops->get_myaddr (this, peeraddr, addrlen, sa, salen);
+out:
+ return ret;
}
int32_t
rpc_transport_get_myname (rpc_transport_t *this, char *hostname, int hostlen)
{
- if (!this)
- return -1;
+ int32_t ret = -1;
+ GF_VALIDATE_OR_GOTO ("rpc", this, out);
- return this->ops->get_myname (this, hostname, hostlen);
+ ret = this->ops->get_myname (this, hostname, hostlen);
+out:
+ return ret;
}
int32_t
rpc_transport_get_peername (rpc_transport_t *this, char *hostname, int hostlen)
{
- if (!this)
- return -1;
- return this->ops->get_peername (this, hostname, hostlen);
+ int32_t ret = -1;
+ GF_VALIDATE_OR_GOTO ("rpc", this, out);
+
+ ret = this->ops->get_peername (this, hostname, hostlen);
+out:
+ return ret;
}
int32_t
rpc_transport_get_peeraddr (rpc_transport_t *this, char *peeraddr, int addrlen,
struct sockaddr_storage *sa, size_t salen)
{
- if (!this)
- return -1;
- return this->ops->get_peeraddr (this, peeraddr, addrlen, sa, salen);
+ int32_t ret = -1;
+ GF_VALIDATE_OR_GOTO ("rpc", this, out);
+
+ ret = this->ops->get_peeraddr (this, peeraddr, addrlen, sa, salen);
+out:
+ return ret;
}
void
rpc_transport_pollin_destroy (rpc_transport_pollin_t *pollin)
{
- if (!pollin) {
- goto out;
- }
+ GF_VALIDATE_OR_GOTO ("rpc", pollin, out);
if (pollin->iobref) {
iobref_unref (pollin->iobref);
@@ -533,7 +542,6 @@ rpc_transport_pollin_alloc (rpc_transport_t *this, struct iovec *vector,
rpc_transport_pollin_t *msg = NULL;
msg = GF_CALLOC (1, sizeof (*msg), gf_common_mt_rpc_trans_pollin_t);
if (!msg) {
- gf_log ("rpc-transport", GF_LOG_ERROR, "out of memory");
goto out;
}
@@ -552,143 +560,6 @@ out:
}
-rpc_transport_pollin_t *
-rpc_transport_same_process_pollin_alloc (rpc_transport_t *this,
- struct iovec *rpchdr, int rpchdrcount,
- struct iovec *proghdr,
- int proghdrcount,
- struct iovec *progpayload,
- int progpayloadcount,
- rpc_transport_rsp_t *rsp,
- char is_request)
-{
- rpc_transport_pollin_t *msg = NULL;
- int rpchdrlen = 0, proghdrlen = 0;
- int progpayloadlen = 0;
- char vectored = 0;
- char *hdr = NULL, *progpayloadbuf = NULL;
- struct iobuf *iobuf = NULL;
-
- if (!rpchdr || !proghdr) {
- goto err;
- }
-
- msg = GF_CALLOC (1, sizeof (*msg), gf_common_mt_rpc_trans_pollin_t);
- if (!msg) {
- gf_log ("rpc-transport", GF_LOG_ERROR, "out of memory");
- goto err;
- }
-
- rpchdrlen = iov_length (rpchdr, rpchdrcount);
- proghdrlen = iov_length (proghdr, proghdrcount);
-
- if (progpayload) {
- vectored = 1;
- progpayloadlen = iov_length (progpayload, progpayloadcount);
- }
-
- /* FIXME: we are assuming rpchdr and proghdr will fit into
- * an iobuf (128KB)
- */
- if ((rpchdrlen + proghdrlen) > this->ctx->page_size) {
- gf_log ("rpc_transport", GF_LOG_DEBUG, "program hdr and rpc"
- " hdr together combined (%d) is bigger than "
- "iobuf size (%zu)", (rpchdrlen + proghdrlen),
- this->ctx->page_size);
- goto err;
- }
-
- if (vectored) {
- msg->iobref = iobref_new ();
- if (!msg->iobref) {
- gf_log ("rpc-transport", GF_LOG_ERROR,
- "out of memory");
- goto err;
- }
-
- iobuf = iobuf_get (this->ctx->iobuf_pool);
- if (!iobuf) {
- gf_log ("rpc_transport", GF_LOG_ERROR,
- "out of memory");
- goto err;
- }
-
- iobref_add (msg->iobref, iobuf);
- iobuf_unref (iobuf);
-
- msg->vector[0].iov_len = rpchdrlen + proghdrlen;
- msg->vector[0].iov_base = hdr = iobuf_ptr (iobuf);
-
- if (!is_request && rsp) {
- msg->vector[1] = rsp->rsp_payload[0];
- progpayloadbuf = rsp->rsp_payload[0].iov_base;
- } else {
- iobuf = iobuf_get (this->ctx->iobuf_pool);
- if (!iobuf) {
- gf_log ("rpc_transport", GF_LOG_ERROR,
- "out of memory");
- goto err;
- }
-
- iobref_add (msg->iobref, iobuf);
- iobuf_unref (iobuf);
-
- msg->vector[1].iov_base
- = progpayloadbuf = iobuf_ptr (iobuf);
- }
- msg->vector[1].iov_len = progpayloadlen;
- } else {
- if (!is_request && rsp) {
- /* FIXME: Assuming rspvec contains only one vector */
- hdr = rsp->rsphdr[0].iov_base;
- msg->vector[0] = rsp->rsphdr[0];
- } else {
- msg->iobref = iobref_new ();
- if (!msg->iobref) {
- gf_log ("rpc-transport", GF_LOG_ERROR,
- "out of memory");
- goto err;
- }
-
- iobuf = iobuf_get (this->ctx->iobuf_pool);
- if (!iobuf) {
- gf_log ("rpc_transport", GF_LOG_ERROR,
- "out of memory");
- goto err;
- }
-
- iobref_add (msg->iobref, iobuf);
- iobuf_unref (iobuf);
-
- hdr = iobuf_ptr (iobuf);
- msg->vector[0].iov_base = hdr;
- }
-
- msg->vector[0].iov_len = rpchdrlen + proghdrlen;
- }
-
- iov_unload (hdr, rpchdr, rpchdrcount);
- hdr += rpchdrlen;
- iov_unload (hdr, proghdr, proghdrcount);
-
- if (progpayload) {
- iov_unload (progpayloadbuf, progpayload,
- progpayloadcount);
- }
-
- if (is_request) {
- msg->private = rsp;
- }
- return msg;
-err:
- if (msg) {
- rpc_transport_pollin_destroy (msg);
- }
-
- return NULL;
-}
-
-
rpc_transport_t *
rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
@@ -707,10 +578,12 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
GF_VALIDATE_OR_GOTO("rpc-transport", trans_name, fail);
trans = GF_CALLOC (1, sizeof (struct rpc_transport), gf_common_mt_rpc_trans_t);
- GF_VALIDATE_OR_GOTO("rpc-transport", trans, fail);
+ if (!trans)
+ goto fail;
trans->name = gf_strdup (trans_name);
- GF_VALIDATE_OR_GOTO ("rpc-transport", trans->name, fail);
+ if (!trans->name)
+ goto fail;
trans->ctx = ctx;
type = str;
@@ -722,9 +595,10 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
if (ret < 0)
gf_log ("dict", GF_LOG_DEBUG,
"setting transport-type failed");
- gf_log ("rpc-transport", GF_LOG_WARNING,
- "missing 'option transport-type'. defaulting to "
- "\"socket\"");
+ else
+ gf_log ("rpc-transport", GF_LOG_WARNING,
+ "missing 'option transport-type'. defaulting to "
+ "\"socket\"");
} else {
{
/* Backword compatibility to handle * /client,
@@ -772,9 +646,9 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
ret = gf_asprintf (&name, "%s/%s.so", RPC_TRANSPORTDIR, type);
if (-1 == ret) {
- gf_log ("rpc-transport", GF_LOG_ERROR, "asprintf failed");
goto fail;
}
+
gf_log ("rpc-transport", GF_LOG_DEBUG,
"attempt to load file %s", name);
@@ -818,7 +692,6 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),
gf_common_mt_volume_opt_list_t);
if (!vol_opt) {
- gf_log (trans_name, GF_LOG_ERROR, "out of memory");
goto fail;
}
@@ -1020,10 +893,7 @@ rpc_transport_notify (rpc_transport_t *this, rpc_transport_event_t event,
void *data, ...)
{
int32_t ret = -1;
-
- if (this == NULL) {
- goto out;
- }
+ GF_VALIDATE_OR_GOTO ("rpc", this, out);
if (this->notify != NULL) {
ret = this->notify (this, this->mydata, event, data);
@@ -1040,11 +910,8 @@ inline int
rpc_transport_register_notify (rpc_transport_t *trans,
rpc_transport_notify_t notify, void *mydata)
{
- int ret = -1;
-
- if (trans == NULL) {
- goto out;
- }
+ int32_t ret = -1;
+ GF_VALIDATE_OR_GOTO ("rpc", trans, out);
trans->notify = notify;
trans->mydata = mydata;
diff --git a/rpc/rpc-lib/src/rpcsvc-auth.c b/rpc/rpc-lib/src/rpcsvc-auth.c
index 5cfa255ba95..0dac37b8294 100644
--- a/rpc/rpc-lib/src/rpcsvc-auth.c
+++ b/rpc/rpc-lib/src/rpcsvc-auth.c
@@ -41,7 +41,6 @@ rpcsvc_auth_add_initer (struct list_head *list, char *idfier,
new = GF_CALLOC (1, sizeof (*new), gf_common_mt_rpcsvc_auth_list);
if (!new) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Memory allocation failed");
return -1;
}
@@ -295,14 +294,14 @@ rpcsvc_authenticate (rpcsvc_request_t *req)
//minauth = rpcsvc_request_prog_minauth (req);
minauth = 1;
if (minauth > rpcsvc_request_cred_flavour (req)) {
- gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Auth too weak");
+ gf_log (GF_RPCSVC, GF_LOG_WARNING, "Auth too weak");
rpcsvc_request_set_autherr (req, AUTH_TOOWEAK);
goto err;
}
auth = rpcsvc_auth_get_handler (req);
if (!auth) {
- gf_log (GF_RPCSVC, GF_LOG_DEBUG, "No auth handler found");
+ gf_log (GF_RPCSVC, GF_LOG_WARNING, "No auth handler found");
goto err;
}
@@ -314,95 +313,6 @@ err:
}
-int
-rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen)
-{
- int count = 0;
- int gen = RPCSVC_AUTH_REJECT;
- int spec = RPCSVC_AUTH_REJECT;
- int final = RPCSVC_AUTH_REJECT;
- char *srchstr = NULL;
- char *valstr = NULL;
- gf_boolean_t boolval = _gf_false;
- int ret = 0;
-
- struct rpcsvc_auth_list *auth = NULL;
- struct rpcsvc_auth_list *tmp = NULL;
-
- if ((!svc) || (!autharr) || (!volname))
- return -1;
-
- memset (autharr, 0, arrlen * sizeof(int));
- if (list_empty (&svc->authschemes)) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "No authentication!");
- goto err;
- }
-
- list_for_each_entry_safe (auth, tmp, &svc->authschemes, authlist) {
- if (count >= arrlen)
- break;
-
- gen = gf_asprintf (&srchstr, "rpc-auth.%s", auth->name);
- if (gen == -1) {
- count = -1;
- goto err;
- }
-
- gen = RPCSVC_AUTH_REJECT;
- if (dict_get (svc->options, srchstr)) {
- ret = dict_get_str (svc->options, srchstr, &valstr);
- if (ret == 0) {
- ret = gf_string2boolean (valstr, &boolval);
- if (ret == 0) {
- if (boolval == _gf_true)
- gen = RPCSVC_AUTH_ACCEPT;
- } else
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile"
- "d to read auth val");
- } else
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile"
- "d to read auth val");
- }
-
- GF_FREE (srchstr);
- spec = gf_asprintf (&srchstr, "rpc-auth.%s.%s", auth->name,
- volname);
- if (spec == -1) {
- count = -1;
- goto err;
- }
-
- spec = RPCSVC_AUTH_DONTCARE;
- if (dict_get (svc->options, srchstr)) {
- ret = dict_get_str (svc->options, srchstr, &valstr);
- if (ret == 0) {
- ret = gf_string2boolean (valstr, &boolval);
- if (ret == 0) {
- if (boolval == _gf_true)
- spec = RPCSVC_AUTH_ACCEPT;
- else
- spec = RPCSVC_AUTH_REJECT;
- } else
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile"
- "d to read auth val");
- } else
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile"
- "d to read auth val");
- }
-
- GF_FREE (srchstr);
- final = rpcsvc_combine_gen_spec_volume_checks (gen, spec);
- if (final == RPCSVC_AUTH_ACCEPT) {
- autharr[count] = auth->auth->authnum;
- ++count;
- }
- }
-
-err:
- return count;
-}
-
-
gid_t *
rpcsvc_auth_unix_auxgids (rpcsvc_request_t *req, int *arrlen)
{
@@ -410,8 +320,10 @@ rpcsvc_auth_unix_auxgids (rpcsvc_request_t *req, int *arrlen)
return NULL;
if ((req->cred.flavour != AUTH_UNIX) ||
- (req->cred.flavour != AUTH_GLUSTERFS))
+ (req->cred.flavour != AUTH_GLUSTERFS)) {
+ gf_log ("", GF_LOG_DEBUG, "auth type not unix or glusterfs");
return NULL;
+ }
*arrlen = req->auxgidcount;
if (*arrlen == 0)
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c
index 3e9d58530f4..cd8629de47d 100644
--- a/rpc/rpc-lib/src/rpcsvc.c
+++ b/rpc/rpc-lib/src/rpcsvc.c
@@ -60,451 +60,6 @@ rpcsvc_listener_t *
rpcsvc_get_listener (rpcsvc_t *svc, uint16_t port, rpc_transport_t *trans);
int
-rpcsvc_transport_peer_check_search (dict_t *options, char *pattern, char *clstr)
-{
- int ret = -1;
- char *addrtok = NULL;
- char *addrstr = NULL;
- char *svptr = NULL;
-
- if ((!options) || (!clstr))
- return -1;
-
- if (!dict_get (options, pattern))
- return -1;
-
- ret = dict_get_str (options, pattern, &addrstr);
- if (ret < 0) {
- ret = -1;
- goto err;
- }
-
- if (!addrstr) {
- ret = -1;
- goto err;
- }
-
- addrtok = strtok_r (addrstr, ",", &svptr);
- while (addrtok) {
-
-#ifdef FNM_CASEFOLD
- ret = fnmatch (addrtok, clstr, FNM_CASEFOLD);
-#else
- ret = fnmatch (addrtok, clstr, 0);
-#endif
- if (ret == 0)
- goto err;
-
- addrtok = strtok_r (NULL, ",", &svptr);
- }
-
- ret = -1;
-err:
-
- return ret;
-}
-
-
-int
-rpcsvc_transport_peer_check_allow (dict_t *options, char *volname, char *clstr)
-{
- int ret = RPCSVC_AUTH_DONTCARE;
- char *srchstr = NULL;
- char globalrule[] = "rpc-auth.addr.allow";
-
- if ((!options) || (!clstr))
- return ret;
-
- /* If volname is NULL, then we're searching for the general rule to
- * determine the current address in clstr is allowed or not for all
- * subvolumes.
- */
- if (volname) {
- ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname);
- if (ret == -1) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed");
- ret = RPCSVC_AUTH_DONTCARE;
- goto out;
- }
- } else
- srchstr = globalrule;
-
- ret = rpcsvc_transport_peer_check_search (options, srchstr, clstr);
- if (volname)
- GF_FREE (srchstr);
-
- if (ret == 0)
- ret = RPCSVC_AUTH_ACCEPT;
- else
- ret = RPCSVC_AUTH_DONTCARE;
-out:
- return ret;
-}
-
-int
-rpcsvc_transport_peer_check_reject (dict_t *options, char *volname, char *clstr)
-{
- int ret = RPCSVC_AUTH_DONTCARE;
- char *srchstr = NULL;
- char generalrule[] = "rpc-auth.addr.reject";
-
- if ((!options) || (!clstr))
- return ret;
-
- if (volname) {
- ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.reject", volname);
- if (ret == -1) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed");
- ret = RPCSVC_AUTH_REJECT;
- goto out;
- }
- } else
- srchstr = generalrule;
-
- ret = rpcsvc_transport_peer_check_search (options, srchstr, clstr);
- if (volname)
- GF_FREE (srchstr);
-
- if (ret == 0)
- ret = RPCSVC_AUTH_REJECT;
- else
- ret = RPCSVC_AUTH_DONTCARE;
-out:
- return ret;
-}
-
-
-/* This function tests the results of the allow rule and the reject rule to
- * combine them into a single result that can be used to determine if the
- * connection should be allowed to proceed.
- * Heres the test matrix we need to follow in this function.
- *
- * A - Allow, the result of the allow test. Never returns R.
- * R - Reject, result of the reject test. Never returns A.
- * Both can return D or dont care if no rule was given.
- *
- * | @allow | @reject | Result |
- * | A | R | R |
- * | D | D | D |
- * | A | D | A |
- * | D | R | R |
- */
-int
-rpcsvc_combine_allow_reject_volume_check (int allow, int reject)
-{
- int final = RPCSVC_AUTH_REJECT;
-
- /* If allowed rule allows but reject rule rejects, we stay cautious
- * and reject. */
- if ((allow == RPCSVC_AUTH_ACCEPT) && (reject == RPCSVC_AUTH_REJECT))
- final = RPCSVC_AUTH_REJECT;
- /* if both are dont care, that is user did not specify for either allow
- * or reject, we leave it up to the general rule to apply, in the hope
- * that there is one.
- */
- else if ((allow == RPCSVC_AUTH_DONTCARE) &&
- (reject == RPCSVC_AUTH_DONTCARE))
- final = RPCSVC_AUTH_DONTCARE;
- /* If one is dont care, the other one applies. */
- else if ((allow == RPCSVC_AUTH_ACCEPT) &&
- (reject == RPCSVC_AUTH_DONTCARE))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((allow == RPCSVC_AUTH_DONTCARE) &&
- (reject == RPCSVC_AUTH_REJECT))
- final = RPCSVC_AUTH_REJECT;
-
- return final;
-}
-
-
-/* Combines the result of the general rule test against, the specific rule
- * to determine final permission for the client's address.
- *
- * | @gen | @spec | Result |
- * | A | A | A |
- * | A | R | R |
- * | A | D | A |
- * | D | A | A |
- * | D | R | R |
- * | D | D | D |
- * | R | A | A |
- * | R | D | R |
- * | R | R | R |
- */
-int
-rpcsvc_combine_gen_spec_addr_checks (int gen, int spec)
-{
- int final = RPCSVC_AUTH_REJECT;
-
- if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_ACCEPT))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_REJECT))
- final = RPCSVC_AUTH_REJECT;
- else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_DONTCARE))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_ACCEPT))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_REJECT))
- final = RPCSVC_AUTH_REJECT;
- else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec== RPCSVC_AUTH_DONTCARE))
- final = RPCSVC_AUTH_DONTCARE;
- else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_ACCEPT))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_DONTCARE))
- final = RPCSVC_AUTH_REJECT;
- else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_REJECT))
- final = RPCSVC_AUTH_REJECT;
-
- return final;
-}
-
-
-
-/* Combines the result of the general rule test against, the specific rule
- * to determine final test for the connection coming in for a given volume.
- *
- * | @gen | @spec | Result |
- * | A | A | A |
- * | A | R | R |
- * | A | D | A |
- * | D | A | A |
- * | D | R | R |
- * | D | D | R |, special case, we intentionally disallow this.
- * | R | A | A |
- * | R | D | R |
- * | R | R | R |
- */
-int
-rpcsvc_combine_gen_spec_volume_checks (int gen, int spec)
-{
- int final = RPCSVC_AUTH_REJECT;
-
- if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_ACCEPT))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_REJECT))
- final = RPCSVC_AUTH_REJECT;
- else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_DONTCARE))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_ACCEPT))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_REJECT))
- final = RPCSVC_AUTH_REJECT;
- /* On no rule, we reject. */
- else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec== RPCSVC_AUTH_DONTCARE))
- final = RPCSVC_AUTH_REJECT;
- else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_ACCEPT))
- final = RPCSVC_AUTH_ACCEPT;
- else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_DONTCARE))
- final = RPCSVC_AUTH_REJECT;
- else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_REJECT))
- final = RPCSVC_AUTH_REJECT;
-
- return final;
-}
-
-
-int
-rpcsvc_transport_peer_check_name (dict_t *options, char *volname,
- rpc_transport_t *trans)
-{
- int ret = RPCSVC_AUTH_REJECT;
- int aret = RPCSVC_AUTH_REJECT;
- int rjret = RPCSVC_AUTH_REJECT;
- char clstr[RPCSVC_PEER_STRLEN];
-
- if (!trans)
- return ret;
-
- ret = rpc_transport_get_peername (trans, clstr, RPCSVC_PEER_STRLEN);
- if (ret != 0) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get remote addr: "
- "%s", gai_strerror (ret));
- ret = RPCSVC_AUTH_REJECT;
- goto err;
- }
-
- aret = rpcsvc_transport_peer_check_allow (options, volname, clstr);
- rjret = rpcsvc_transport_peer_check_reject (options, volname, clstr);
-
- ret = rpcsvc_combine_allow_reject_volume_check (aret, rjret);
-
-err:
- return ret;
-}
-
-
-int
-rpcsvc_transport_peer_check_addr (dict_t *options, char *volname,
- rpc_transport_t *trans)
-{
- int ret = RPCSVC_AUTH_REJECT;
- int aret = RPCSVC_AUTH_DONTCARE;
- int rjret = RPCSVC_AUTH_REJECT;
- char clstr[RPCSVC_PEER_STRLEN];
-
- if (!trans)
- return ret;
-
- ret = rpcsvc_transport_peeraddr (trans, clstr, RPCSVC_PEER_STRLEN, NULL,
- 0);
- if (ret != 0) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get remote addr: "
- "%s", gai_strerror (ret));
- ret = RPCSVC_AUTH_REJECT;
- goto err;
- }
-
- aret = rpcsvc_transport_peer_check_allow (options, volname, clstr);
- rjret = rpcsvc_transport_peer_check_reject (options, volname, clstr);
-
- ret = rpcsvc_combine_allow_reject_volume_check (aret, rjret);
-err:
- return ret;
-}
-
-
-int
-rpcsvc_transport_check_volume_specific (dict_t *options, char *volname,
- rpc_transport_t *trans)
-{
- int namechk = RPCSVC_AUTH_REJECT;
- int addrchk = RPCSVC_AUTH_REJECT;
- gf_boolean_t namelookup = _gf_true;
- char *namestr = NULL;
- int ret = 0;
-
- if ((!options) || (!volname) || (!trans))
- return RPCSVC_AUTH_REJECT;
-
- /* Enabled by default */
- if ((dict_get (options, "rpc-auth.addr.namelookup"))) {
- ret = dict_get_str (options, "rpc-auth.addr.namelookup"
- , &namestr);
- if (ret == 0) {
- ret = gf_string2boolean (namestr, &namelookup);
- if (ret)
- gf_log ("rpcsvc", GF_LOG_DEBUG,
- "wrong option %s given for "
- "'namelookup'", namestr);
- }
- }
-
- /* We need two separate checks because the rules with addresses in them
- * can be network addresses which can be general and names can be
- * specific which will over-ride the network address rules.
- */
- if (namelookup)
- namechk = rpcsvc_transport_peer_check_name (options, volname,
- trans);
- addrchk = rpcsvc_transport_peer_check_addr (options, volname, trans);
-
- if (namelookup)
- ret = rpcsvc_combine_gen_spec_addr_checks (addrchk, namechk);
- else
- ret = addrchk;
-
- return ret;
-}
-
-
-int
-rpcsvc_transport_check_volume_general (dict_t *options, rpc_transport_t *trans)
-{
- int addrchk = RPCSVC_AUTH_REJECT;
- int namechk = RPCSVC_AUTH_REJECT;
- gf_boolean_t namelookup = _gf_true;
- char *namestr = NULL;
- int ret = 0;
-
- if ((!options) || (!trans))
- return RPCSVC_AUTH_REJECT;
-
- /* Enabled by default */
- if ((dict_get (options, "rpc-auth.addr.namelookup"))) {
- ret = dict_get_str (options, "rpc-auth.addr.namelookup"
- , &namestr);
- if (!ret) {
- ret = gf_string2boolean (namestr, &namelookup);
- if (ret)
- gf_log ("rpcsvc", GF_LOG_DEBUG,
- "wrong option %s given for "
- "'namelookup'", namestr);
- }
- }
-
- /* We need two separate checks because the rules with addresses in them
- * can be network addresses which can be general and names can be
- * specific which will over-ride the network address rules.
- */
- if (namelookup)
- namechk = rpcsvc_transport_peer_check_name (options, NULL,
- trans);
-
- addrchk = rpcsvc_transport_peer_check_addr (options, NULL, trans);
-
- if (namelookup)
- ret = rpcsvc_combine_gen_spec_addr_checks (addrchk, namechk);
- else
- ret = addrchk;
-
- return ret;
-}
-
-int
-rpcsvc_transport_peer_check (dict_t *options, char *volname,
- rpc_transport_t *trans)
-{
- int general_chk = RPCSVC_AUTH_REJECT;
- int specific_chk = RPCSVC_AUTH_REJECT;
-
- if ((!options) || (!volname) || (!trans))
- return RPCSVC_AUTH_REJECT;
-
- general_chk = rpcsvc_transport_check_volume_general (options, trans);
- specific_chk = rpcsvc_transport_check_volume_specific (options, volname,
- trans);
-
- return rpcsvc_combine_gen_spec_volume_checks (general_chk,specific_chk);
-}
-
-
-char *
-rpcsvc_volume_allowed (dict_t *options, char *volname)
-{
- char globalrule[] = "rpc-auth.addr.allow";
- char *srchstr = NULL;
- char *addrstr = NULL;
- int ret = -1;
-
- if ((!options) || (!volname))
- return NULL;
-
- ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname);
- if (ret == -1) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed");
- goto out;
- }
-
- if (!dict_get (options, srchstr)) {
- GF_FREE (srchstr);
- srchstr = globalrule;
- ret = dict_get_str (options, srchstr, &addrstr);
- if (ret)
- gf_log ("rpcsvc", GF_LOG_DEBUG,
- "failed to get the string %s", srchstr);
- } else {
- ret = dict_get_str (options, srchstr, &addrstr);
- if (ret)
- gf_log ("rpcsvc", GF_LOG_DEBUG,
- "failed to get the string %s", srchstr);
- GF_FREE (srchstr);
- }
-out:
- return addrstr;
-}
-
-
-int
rpcsvc_notify (rpc_transport_t *trans, void *mydata,
rpc_transport_event_t event, void *data, ...);
@@ -515,7 +70,6 @@ rpcsvc_notify_wrapper_alloc (void)
wrapper = GF_CALLOC (1, sizeof (*wrapper), gf_common_mt_rpcsvc_wrapper_t);
if (!wrapper) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation failed");
goto out;
}
@@ -552,102 +106,6 @@ out:
}
-int
-rpcsvc_conn_privport_check (rpcsvc_t *svc, char *volname,
- rpc_transport_t *trans)
-{
- struct sockaddr_storage sa = {0, };
- int ret = RPCSVC_AUTH_REJECT;
- socklen_t sasize = sizeof (sa);
- char *srchstr = NULL;
- char *valstr = NULL;
- int globalinsecure = RPCSVC_AUTH_REJECT;
- int exportinsecure = RPCSVC_AUTH_DONTCARE;
- uint16_t port = 0;
- gf_boolean_t insecure = _gf_false;
-
- if ((!svc) || (!volname) || (!trans))
- return ret;
-
- ret = rpcsvc_transport_peeraddr (trans, NULL, 0, &sa,
- sasize);
- if (ret != 0) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get peer addr: %s",
- gai_strerror (ret));
- ret = RPCSVC_AUTH_REJECT;
- goto err;
- }
-
- if (sa.ss_family == AF_INET) {
- port = ((struct sockaddr_in *)&sa)->sin_port;
- } else {
- port = ((struct sockaddr_in6 *)&sa)->sin6_port;
- }
-
- gf_log (GF_RPCSVC, GF_LOG_TRACE, "Client port: %d", (int)port);
- /* If the port is already a privileged one, dont bother with checking
- * options.
- */
- if (port <= 1024) {
- ret = RPCSVC_AUTH_ACCEPT;
- goto err;
- }
-
- /* Disabled by default */
- if ((dict_get (svc->options, "rpc-auth.ports.insecure"))) {
- ret = dict_get_str (svc->options, "rpc-auth.ports.insecure"
- , &srchstr);
- if (ret == 0) {
- ret = gf_string2boolean (srchstr, &insecure);
- if (ret == 0) {
- if (insecure == _gf_true)
- globalinsecure = RPCSVC_AUTH_ACCEPT;
- } else
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to"
- " read rpc-auth.ports.insecure value");
- } else
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to"
- " read rpc-auth.ports.insecure value");
- }
-
- /* Disabled by default */
- ret = gf_asprintf (&srchstr, "rpc-auth.ports.%s.insecure", volname);
- if (ret == -1) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed");
- ret = RPCSVC_AUTH_REJECT;
- goto err;
- }
-
- if (dict_get (svc->options, srchstr)) {
- ret = dict_get_str (svc->options, srchstr, &valstr);
- if (ret == 0) {
- ret = gf_string2boolean (srchstr, &insecure);
- if (ret == 0) {
- if (insecure == _gf_true)
- exportinsecure = RPCSVC_AUTH_ACCEPT;
- else
- exportinsecure = RPCSVC_AUTH_REJECT;
- } else
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to"
- " read rpc-auth.ports.insecure value");
- } else
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to"
- " read rpc-auth.ports.insecure value");
- }
-
- ret = rpcsvc_combine_gen_spec_volume_checks (globalinsecure,
- exportinsecure);
- if (ret == RPCSVC_AUTH_ACCEPT)
- gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Unprivileged port allowed");
- else
- gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Unprivileged port not"
- " allowed");
-
-err:
- if (srchstr)
- GF_FREE (srchstr);
- return ret;
-}
/* This needs to change to returning errors, since
@@ -685,26 +143,31 @@ rpcsvc_program_actor (rpcsvc_request_t *req)
if (!found) {
if (err != PROG_MISMATCH) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR,
- "RPC program not available");
+ gf_log (GF_RPCSVC, GF_LOG_WARNING,
+ "RPC program not available (req %u %u)",
+ req->prognum, req->progver);
err = PROG_UNAVAIL;
goto err;
}
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC program version not"
- " available");
+ gf_log (GF_RPCSVC, GF_LOG_WARNING,
+ "RPC program version not available (req %u %u)",
+ req->prognum, req->progver);
goto err;
}
req->prog = program;
if (!program->actors) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC System error");
+ gf_log (GF_RPCSVC, GF_LOG_WARNING,
+ "RPC Actor not found for program %s %d",
+ program->progname, program->prognum);
err = SYSTEM_ERR;
goto err;
}
if ((req->procnum < 0) || (req->procnum >= program->numactors)) {
gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC Program procedure not"
- " available");
+ " available for procedure %d in %s", req->procnum,
+ program->progname);
err = PROC_UNAVAIL;
goto err;
}
@@ -712,7 +175,8 @@ rpcsvc_program_actor (rpcsvc_request_t *req)
actor = &program->actors[req->procnum];
if (!actor->actor) {
gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC Program procedure not"
- " available");
+ " available for procedure %d in %s", req->procnum,
+ program->progname);
err = PROC_UNAVAIL;
actor = NULL;
goto err;
@@ -864,7 +328,6 @@ rpcsvc_request_create (rpcsvc_t *svc, rpc_transport_t *trans,
*/
rpcsvc_alloc_request (svc, req);
if (!req) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to alloc request");
goto err;
}
@@ -875,7 +338,7 @@ rpcsvc_request_create (rpcsvc_t *svc, rpc_transport_t *trans,
req->cred.authdata,req->verf.authdata);
if (ret == -1) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC call decoding failed");
+ gf_log (GF_RPCSVC, GF_LOG_WARNING, "RPC call decoding failed");
rpcsvc_request_seterr (req, GARBAGE_ARGS);
req->trans = rpc_transport_ref (trans);
req->svc = svc;
@@ -893,7 +356,14 @@ rpcsvc_request_create (rpcsvc_t *svc, rpc_transport_t *trans,
trans->name);
if (rpc_call_rpcvers (&rpcmsg) != 2) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC version not supported");
+ /* LOG- TODO: print rpc version, also print the peerinfo
+ from transport */
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC version not supported "
+ "(XID: 0x%lx, Ver: %ld, Prog: %ld, ProgVers: %ld, "
+ "Proc: %ld) from trans (%s)", rpc_call_xid (&rpcmsg),
+ rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg),
+ rpc_call_progver (&rpcmsg), rpc_call_progproc (&rpcmsg),
+ trans->name);
rpcsvc_request_seterr (req, RPC_MISMATCH);
goto err;
}
@@ -905,7 +375,12 @@ rpcsvc_request_create (rpcsvc_t *svc, rpc_transport_t *trans,
* error happened.
*/
rpcsvc_request_seterr (req, AUTH_ERROR);
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed authentication");
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "auth failed on request. "
+ "(XID: 0x%lx, Ver: %ld, Prog: %ld, ProgVers: %ld, "
+ "Proc: %ld) from trans (%s)", rpc_call_xid (&rpcmsg),
+ rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg),
+ rpc_call_progver (&rpcmsg), rpc_call_progproc (&rpcmsg),
+ trans->name);
ret = -1;
goto err;
}
@@ -920,7 +395,7 @@ err:
if (ret == -1) {
ret = rpcsvc_error_reply (req);
if (ret)
- gf_log ("rpcsvc", GF_LOG_DEBUG,
+ gf_log ("rpcsvc", GF_LOG_WARNING,
"failed to queue error reply");
req = NULL;
}
@@ -954,7 +429,7 @@ rpcsvc_handle_rpc_call (rpcsvc_t *svc, rpc_transport_t *trans,
is_unix = _gf_true;
break;
default:
- gf_log (GF_RPCSVC, GF_LOG_DEBUG,
+ gf_log (GF_RPCSVC, GF_LOG_ERROR,
"invalid address family (%d)",
trans->peerinfo.sockaddr.ss_family);
return -1;
@@ -995,6 +470,8 @@ rpcsvc_handle_rpc_call (rpcsvc_t *svc, rpc_transport_t *trans,
req->iobref);
} else {
rpcsvc_request_seterr (req, PROC_UNAVAIL);
+ /* LOG TODO: print more info about procnum,
+ prognum etc, also print transport info */
gf_log (GF_RPCSVC, GF_LOG_ERROR,
"No vectored handler present");
ret = RPCSVC_ACTOR_ERROR;
@@ -1010,7 +487,7 @@ err_reply:
}
if (ret)
- gf_log ("rpcsvc", GF_LOG_DEBUG, "failed to queue error reply");
+ gf_log ("rpcsvc", GF_LOG_WARNING, "failed to queue error reply");
/* No need to propagate error beyond this function since the reply
* has now been queued. */
@@ -1107,6 +584,7 @@ rpcsvc_notify (rpc_transport_t *trans, void *mydata,
/* do nothing, no need for rpcsvc to handle this, client should
* handle this event
*/
+ /* print info about transport too : LOG TODO */
gf_log ("rpcsvc", GF_LOG_CRITICAL,
"got CONNECT event, which should have not come");
ret = 0;
@@ -1153,7 +631,7 @@ rpcsvc_record_build_header (char *recordstart, size_t rlen,
*/
ret = rpc_reply_to_xdr (&reply, recordstart, rlen, &replyhdr);
if (ret == -1) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to create RPC reply");
+ gf_log (GF_RPCSVC, GF_LOG_WARNING, "Failed to create RPC reply");
goto err;
}
@@ -1224,7 +702,7 @@ rpcsvc_callback_build_header (char *recordstart, size_t rlen,
ret = rpc_request_to_xdr (request, recordstart, rlen, &requesthdr);
if (ret == -1) {
- gf_log ("rpcsvc", GF_LOG_DEBUG,
+ gf_log ("rpcsvc", GF_LOG_WARNING,
"Failed to create RPC request");
goto out;
}
@@ -1267,7 +745,6 @@ rpcsvc_callback_build_record (rpcsvc_t *rpc, int prognum, int progver,
*/
request_iob = iobuf_get (rpc->ctx->iobuf_pool);
if (!request_iob) {
- gf_log ("rpcsvc", GF_LOG_ERROR, "Failed to get iobuf");
goto out;
}
@@ -1279,7 +756,7 @@ rpcsvc_callback_build_record (rpcsvc_t *rpc, int prognum, int progver,
ret = rpcsvc_fill_callback (prognum, progver, procnum, payload, xid,
&request);
if (ret == -1) {
- gf_log ("rpcsvc", GF_LOG_DEBUG, "cannot build a rpc-request "
+ gf_log ("rpcsvc", GF_LOG_WARNING, "cannot build a rpc-request "
"xid (%"PRIu64")", xid);
goto out;
}
@@ -1332,7 +809,7 @@ rpcsvc_callback_submit (rpcsvc_t *rpc, rpc_transport_t *trans,
proglen, callid,
&rpchdr);
if (!request_iob) {
- gf_log ("rpcsvc", GF_LOG_DEBUG,
+ gf_log ("rpcsvc", GF_LOG_WARNING,
"cannot build rpc-record");
goto out;
}
@@ -1344,7 +821,7 @@ rpcsvc_callback_submit (rpcsvc_t *rpc, rpc_transport_t *trans,
ret = rpc_transport_submit_request (trans, &req);
if (ret == -1) {
- gf_log ("rpc-clnt", GF_LOG_DEBUG,
+ gf_log ("rpcsvc", GF_LOG_WARNING,
"transmission of rpc-request failed");
goto out;
}
@@ -1444,7 +921,6 @@ rpcsvc_record_build_record (rpcsvc_request_t *req, size_t payload,
replyiob = iobuf_get (svc->ctx->iobuf_pool);
pagesize = iobpool_pagesize ((struct iobuf_pool *)svc->ctx->iobuf_pool);
if (!replyiob) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get iobuf");
goto err_exit;
}
@@ -1536,8 +1012,6 @@ rpcsvc_submit_generic (rpcsvc_request_t *req, struct iovec *proghdr,
if (!iobref) {
iobref = iobref_new ();
if (!iobref) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation "
- "failed");
goto disconnect_exit;
}
@@ -1589,6 +1063,8 @@ rpcsvc_error_reply (rpcsvc_request_t *req)
if (!req)
return -1;
+ gf_log_callingfn ("", GF_LOG_WARNING, "sending a RPC error reply");
+
/* At this point the req should already have been filled with the
* appropriate RPC error numbers.
*/
@@ -1622,16 +1098,20 @@ out:
inline int
rpcsvc_program_unregister_portmap (rpcsvc_program_t *prog)
{
+ int ret = 0;
+
if (!prog)
- return -1;
+ goto out;
if (!(pmap_unset(prog->prognum, prog->progver))) {
gf_log (GF_RPCSVC, GF_LOG_ERROR, "Could not unregister with"
" portmap");
- return -1;
+ goto out;
}
- return 0;
+ ret = 0;
+out:
+ return ret;
}
@@ -1692,7 +1172,7 @@ rpcsvc_get_listener (rpcsvc_t *svc, uint16_t port, rpc_transport_t *trans)
listener_port = rpcsvc_get_listener_port (listener);
if (listener_port == -1) {
- gf_log (GF_RPCSVC, GF_LOG_DEBUG,
+ gf_log (GF_RPCSVC, GF_LOG_ERROR,
"invalid port for listener %s",
listener->trans->name);
continue;
@@ -1804,21 +1284,21 @@ rpcsvc_transport_create (rpcsvc_t *svc, dict_t *options, char *name)
trans = rpc_transport_load (svc->ctx, options, name);
if (!trans) {
- gf_log (GF_RPCSVC, GF_LOG_DEBUG, "cannot create listener, "
+ gf_log (GF_RPCSVC, GF_LOG_WARNING, "cannot create listener, "
"initing the transport failed");
goto out;
}
ret = rpc_transport_listen (trans);
if (ret == -1) {
- gf_log (GF_RPCSVC, GF_LOG_DEBUG,
+ gf_log (GF_RPCSVC, GF_LOG_WARNING,
"listening on transport failed");
goto out;
}
ret = rpc_transport_register_notify (trans, rpcsvc_notify, svc);
if (ret == -1) {
- gf_log (GF_RPCSVC, GF_LOG_DEBUG, "registering notify failed");
+ gf_log (GF_RPCSVC, GF_LOG_WARNING, "registering notify failed");
goto out;
}
@@ -1840,7 +1320,6 @@ rpcsvc_listener_alloc (rpcsvc_t *svc, rpc_transport_t *trans)
listener = GF_CALLOC (1, sizeof (*listener),
gf_common_mt_rpcsvc_listener_t);
if (!listener) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation failed");
goto out;
}
@@ -1872,6 +1351,7 @@ rpcsvc_create_listener (rpcsvc_t *svc, dict_t *options, char *name)
trans = rpcsvc_transport_create (svc, options, name);
if (!trans) {
+ /* LOG TODO */
goto out;
}
@@ -1919,13 +1399,11 @@ rpcsvc_create_listeners (rpcsvc_t *svc, dict_t *options, char *name)
/* duplicate transport_type, since following dict_set will free it */
transport_type = gf_strdup (transport_type);
if (transport_type == NULL) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "out of memory");
goto out;
}
str = gf_strdup (transport_type);
if (str == NULL) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "out of memory");
goto out;
}
@@ -1934,7 +1412,6 @@ rpcsvc_create_listeners (rpcsvc_t *svc, dict_t *options, char *name)
while (ptr != NULL) {
tmp = gf_strdup (ptr);
if (tmp == NULL) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "out of memory");
goto out;
}
@@ -2072,7 +1549,6 @@ rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t *program)
newprog = GF_CALLOC (1, sizeof(*newprog),gf_common_mt_rpcsvc_program_t);
if (newprog == NULL) {
- gf_log (GF_RPCSVC, GF_LOG_ERROR, "out of memory");
goto out;
}
diff --git a/rpc/rpc-lib/src/xdr-rpc.c b/rpc/rpc-lib/src/xdr-rpc.c
index 26e7fa57d85..d26fb69ec4d 100644
--- a/rpc/rpc-lib/src/xdr-rpc.c
+++ b/rpc/rpc-lib/src/xdr-rpc.c
@@ -33,6 +33,7 @@
#include "xdr-rpc.h"
#include "xdr-common.h"
#include "logging.h"
+#include "common-utils.h"
/* Decodes the XDR format in msgbuf into rpc_msg.
* The remaining payload is returned into payload.
@@ -44,9 +45,10 @@ xdr_to_rpc_call (char *msgbuf, size_t len, struct rpc_msg *call,
XDR xdr;
char opaquebytes[MAX_AUTH_BYTES];
struct opaque_auth *oa = NULL;
+ int ret = -1;
- if ((!msgbuf) || (!call))
- return -1;
+ GF_VALIDATE_OR_GOTO ("rpc", msgbuf, out);
+ GF_VALIDATE_OR_GOTO ("rpc", call, out);
memset (call, 0, sizeof (*call));
@@ -63,15 +65,19 @@ xdr_to_rpc_call (char *msgbuf, size_t len, struct rpc_msg *call,
oa->oa_base = verfbytes;
xdrmem_create (&xdr, msgbuf, len, XDR_DECODE);
- if (!xdr_callmsg (&xdr, call))
- return -1;
+ if (!xdr_callmsg (&xdr, call)) {
+ gf_log ("rpc", GF_LOG_WARNING, "failed to decode call msg");
+ goto out;
+ }
if (payload) {
payload->iov_base = xdr_decoded_remaining_addr (xdr);
payload->iov_len = xdr_decoded_remaining_len (xdr);
}
- return 0;
+ ret = 0;
+out:
+ return ret;
}
@@ -85,8 +91,9 @@ true_func (XDR *s, caddr_t *a)
int
rpc_fill_empty_reply (struct rpc_msg *reply, uint32_t xid)
{
- if (!reply)
- return -1;
+ int ret = -1;
+
+ GF_VALIDATE_OR_GOTO ("rpc", reply, out);
/* Setting to 0 also results in reply verifier flavor to be
* set to AUTH_NULL which is what we want right now.
@@ -95,14 +102,17 @@ rpc_fill_empty_reply (struct rpc_msg *reply, uint32_t xid)
reply->rm_xid = xid;
reply->rm_direction = REPLY;
- return 0;
+ ret = 0;
+out:
+ return ret;
}
int
rpc_fill_denied_reply (struct rpc_msg *reply, int rjstat, int auth_err)
{
- if (!reply)
- return -1;
+ int ret = -1;
+
+ GF_VALIDATE_OR_GOTO ("rpc", reply, out);
reply->rm_reply.rp_stat = MSG_DENIED;
reply->rjcted_rply.rj_stat = rjstat;
@@ -116,7 +126,9 @@ rpc_fill_denied_reply (struct rpc_msg *reply, int rjstat, int auth_err)
} else if (rjstat == AUTH_ERROR)
reply->rjcted_rply.rj_why = auth_err;
- return 0;
+ ret = 0;
+out:
+ return ret;
}
@@ -124,8 +136,9 @@ int
rpc_fill_accepted_reply (struct rpc_msg *reply, int arstat, int proglow,
int proghigh, int verf, int len, char *vdata)
{
- if (!reply)
- return -1;
+ int ret = -1;
+
+ GF_VALIDATE_OR_GOTO ("rpc", reply, out);
reply->rm_reply.rp_stat = MSG_ACCEPTED;
reply->acpted_rply.ar_stat = arstat;
@@ -145,26 +158,34 @@ rpc_fill_accepted_reply (struct rpc_msg *reply, int arstat, int proglow,
reply->acpted_rply.ar_results.where = NULL;
}
- return 0;
+ ret = 0;
+out:
+ return ret;
}
int
rpc_reply_to_xdr (struct rpc_msg *reply, char *dest, size_t len,
struct iovec *dst)
{
- XDR xdr;
+ XDR xdr;
+ int ret = -1;
- if ((!dest) || (!reply) || (!dst))
- return -1;
+ GF_VALIDATE_OR_GOTO ("rpc", reply, out);
+ GF_VALIDATE_OR_GOTO ("rpc", dest, out);
+ GF_VALIDATE_OR_GOTO ("rpc", dst, out);
xdrmem_create (&xdr, dest, len, XDR_ENCODE);
- if (!xdr_replymsg(&xdr, reply))
- return -1;
+ if (!xdr_replymsg(&xdr, reply)) {
+ gf_log ("rpc", GF_LOG_WARNING, "failed to encode reply msg");
+ goto out;
+ }
dst->iov_base = dest;
dst->iov_len = xdr_encoded_length (xdr);
- return 0;
+ ret = 0;
+out:
+ return ret;
}
@@ -173,9 +194,12 @@ xdr_to_auth_unix_cred (char *msgbuf, int msglen, struct authunix_parms *au,
char *machname, gid_t *gids)
{
XDR xdr;
+ int ret = -1;
- if ((!msgbuf) || (!machname) || (!gids) || (!au))
- return -1;
+ GF_VALIDATE_OR_GOTO ("rpc", msgbuf, out);
+ GF_VALIDATE_OR_GOTO ("rpc", machname, out);
+ GF_VALIDATE_OR_GOTO ("rpc", gids, out);
+ GF_VALIDATE_OR_GOTO ("rpc", au, out);
au->aup_machname = machname;
#ifdef GF_DARWIN_HOST_OS
@@ -186,8 +210,12 @@ xdr_to_auth_unix_cred (char *msgbuf, int msglen, struct authunix_parms *au,
xdrmem_create (&xdr, msgbuf, msglen, XDR_DECODE);
- if (!xdr_authunix_parms (&xdr, au))
- return -1;
+ if (!xdr_authunix_parms (&xdr, au)) {
+ gf_log ("rpc", GF_LOG_WARNING, "failed to decode auth unix parms");
+ goto out;
+ }
- return 0;
+ ret = 0;
+out:
+ return ret;
}
diff --git a/rpc/rpc-lib/src/xdr-rpcclnt.c b/rpc/rpc-lib/src/xdr-rpcclnt.c
index 933887b0b19..416d19ffbf7 100644
--- a/rpc/rpc-lib/src/xdr-rpcclnt.c
+++ b/rpc/rpc-lib/src/xdr-rpcclnt.c
@@ -34,6 +34,7 @@
#include "xdr-rpc.h"
#include "xdr-common.h"
#include "logging.h"
+#include "common-utils.h"
/* Decodes the XDR format in msgbuf into rpc_msg.
* The remaining payload is returned into payload.
@@ -43,12 +44,10 @@ xdr_to_rpc_reply (char *msgbuf, size_t len, struct rpc_msg *reply,
struct iovec *payload, char *verfbytes)
{
XDR xdr;
- int ret = -1;
+ int ret = -EINVAL;
- if ((!msgbuf) || (!reply)) {
- ret = -EINVAL;
- goto out;
- }
+ GF_VALIDATE_OR_GOTO ("rpc", msgbuf, out);
+ GF_VALIDATE_OR_GOTO ("rpc", reply, out);
memset (reply, 0, sizeof (struct rpc_msg));
@@ -58,6 +57,7 @@ xdr_to_rpc_reply (char *msgbuf, size_t len, struct rpc_msg *reply,
xdrmem_create (&xdr, msgbuf, len, XDR_DECODE);
if (!xdr_replymsg (&xdr, reply)) {
+ gf_log ("rpc", GF_LOG_WARNING, "failed to decode reply msg");
ret = -errno;
goto out;
}
@@ -71,13 +71,6 @@ out:
return ret;
}
-#if 0
-bool_t
-true_func (XDR *s, caddr_t *a)
-{
- return TRUE;
-}
-#endif
int
rpc_request_to_xdr (struct rpc_msg *request, char *dest, size_t len,
@@ -86,12 +79,13 @@ rpc_request_to_xdr (struct rpc_msg *request, char *dest, size_t len,
XDR xdr;
int ret = -1;
- if ((!dest) || (!request) || (!dst)) {
- goto out;
- }
+ GF_VALIDATE_OR_GOTO ("rpc", dest, out);
+ GF_VALIDATE_OR_GOTO ("rpc", request, out);
+ GF_VALIDATE_OR_GOTO ("rpc", dst, out);
xdrmem_create (&xdr, dest, len, XDR_ENCODE);
if (!xdr_callmsg (&xdr, request)) {
+ gf_log ("rpc", GF_LOG_WARNING, "failed to encode call msg");
goto out;
}
@@ -112,13 +106,14 @@ auth_unix_cred_to_xdr (struct authunix_parms *au, char *dest, size_t len,
XDR xdr;
int ret = -1;
- if (!au || !dest || !iov) {
- goto out;
- }
+ GF_VALIDATE_OR_GOTO ("rpc", au, out);
+ GF_VALIDATE_OR_GOTO ("rpc", dest, out);
+ GF_VALIDATE_OR_GOTO ("rpc", iov, out);
xdrmem_create (&xdr, dest, len, XDR_DECODE);
if (!xdr_authunix_parms (&xdr, au)) {
+ gf_log ("rpc", GF_LOG_WARNING, "failed to decode authunix parms");
goto out;
}