------------------------------------------------------------ revno: 152 revision-id: [EMAIL PROTECTED] parent: [EMAIL PROTECTED] committer: Andrew Tridgell <[EMAIL PROTECTED]> branch nick: tridge timestamp: Wed 2007-04-18 18:39:02 +1000 message: validate dmaster on a client fetch request modified: common/ctdb_daemon.c ctdb_daemon.c-20070409200331-3el1kqgdb9m4ib0g-1 common/ctdb_util.c ctdb_util.c-20061128065342-to93h6eejj5kon81-3 include/ctdb_private.h ctdb_private.h-20061117234101-o3qt14umlg9en8z0-13 === modified file 'common/ctdb_daemon.c' --- a/common/ctdb_daemon.c 2007-04-18 05:35:41 +0000 +++ b/common/ctdb_daemon.c 2007-04-18 08:39:02 +0000 @@ -244,6 +244,30 @@ _exit(0); } + +/* + send a fetch lock error reply to the client + */ +static void daemon_fetch_lock_error(struct ctdb_client *client, + struct ctdb_req_fetch_lock *f) +{ + struct ctdb_reply_fetch_lock r; + + ZERO_STRUCT(r); + r.hdr.length = sizeof(r); + r.hdr.ctdb_magic = CTDB_MAGIC; + r.hdr.ctdb_version = CTDB_VERSION; + r.hdr.operation = CTDB_REPLY_FETCH_LOCK; + r.hdr.reqid = f->hdr.reqid; + r.state = -1; + + /* + * Ignore the result, there's not much we can do anyway. + */ + ctdb_queue_send(client->queue, (uint8_t *)&r.hdr, + r.hdr.length); +} + /* called when the daemon gets a fetch lock request from a client */ @@ -257,21 +281,13 @@ ctdb_db = find_ctdb_db(client->ctdb, f->db_id); if (ctdb_db == NULL) { - struct ctdb_reply_fetch_lock r; - - ZERO_STRUCT(r); - r.hdr.length = sizeof(r); - r.hdr.ctdb_magic = CTDB_MAGIC; - r.hdr.ctdb_version = CTDB_VERSION; - r.hdr.operation = CTDB_REPLY_FETCH_LOCK; - r.hdr.reqid = f->hdr.reqid; - r.state = -1; - - /* - * Ignore the result, there's not much we can do anyway. - */ - ctdb_queue_send(client->queue, (uint8_t *)&r.hdr, - r.hdr.length); + daemon_fetch_lock_error(client, f); + return; + } + + if (!ctdb_validate_vnn(client->ctdb, f->header.dmaster)) { + DEBUG(0,(__location__ " Invalid dmaster %u\n", f->header.dmaster)); + daemon_fetch_lock_error(client, f); return; }
=== modified file 'common/ctdb_util.c' --- a/common/ctdb_util.c 2007-04-17 12:13:06 +0000 +++ b/common/ctdb_util.c 2007-04-18 08:39:02 +0000 @@ -102,3 +102,4 @@ return (1103515243 * value + 12345); } + === modified file 'include/ctdb_private.h' --- a/include/ctdb_private.h 2007-04-18 05:35:41 +0000 +++ b/include/ctdb_private.h 2007-04-18 08:39:02 +0000 @@ -50,6 +50,11 @@ int port; }; +/* + check a vnn is valid + */ +#define ctdb_validate_vnn(ctdb, vnn) (((uint32_t)(vnn)) < (ctdb)->num_nodes) + /* called from the queue code when a packet comes in. Called with data==NULL on error */