Commit efff15e4 authored by Ryan Jackson's avatar Ryan Jackson

Modified all functions in libtmcd to be reentrant and thread-safe. Also a bit of general clean-up

parent 8ec627ba
This diff is collapsed.
...@@ -2,14 +2,35 @@ ...@@ -2,14 +2,35 @@
#define _LIBTMCD_H_ #define _LIBTMCD_H_
#include <netinet/in.h> #include <netinet/in.h>
#include <mysql/mysql.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "tbdefs.h" #include "tbdefs.h"
#ifdef EVENTSYS
#include "event.h"
#endif
#define DBNAME_SIZE 64
#define HOSTID_SIZE (32+64)
/* /*
* This structure is passed to each request function. The intent is to * This structure is passed to each request function. The intent is to
* reduce the number of DB queries per request to a minimum. * reduce the number of DB queries per request to a minimum.
*/ */
typedef struct { typedef struct {
MYSQL db;
int db_connected;
char dbname[DBNAME_SIZE];
char prev_dbname[DBNAME_SIZE];
struct in_addr myipaddr;
#ifdef EVENTSYS
event_handle_t event_handle;
#endif
char fshostid[HOSTID_SIZE];
int verbose;
int debug;
int isssl;
int istcp;
int version; int version;
struct in_addr client; struct in_addr client;
int allocated; int allocated;
...@@ -17,8 +38,6 @@ typedef struct { ...@@ -17,8 +38,6 @@ typedef struct {
int isvnode; int isvnode;
int issubnode; int issubnode;
int islocal; int islocal;
int isssl;
int istcp;
int iscontrol; int iscontrol;
int isplabdslice; int isplabdslice;
int isplabsvc; int isplabsvc;
...@@ -51,12 +70,11 @@ typedef struct { ...@@ -51,12 +70,11 @@ typedef struct {
int length; int length;
} tmcdresp_t; } tmcdresp_t;
int iptonodeid(struct in_addr, tmcdreq_t *); int iptonodeid(tmcdreq_t *, struct in_addr);
int nodeidtoexp(char *nodeid, char *pid, char *eid, char *gid); int checkprivkey(tmcdreq_t *reqp, struct in_addr, char *);
int checkprivkey(struct in_addr, char *);
int checkdbredirect(tmcdreq_t *); int checkdbredirect(tmcdreq_t *);
void tmcd_free_response(tmcdresp_t *); void tmcd_free_response(tmcdresp_t *);
tmcdresp_t *tmcd_handle_request(int, char *, char *, tmcdreq_t *); tmcdresp_t *tmcd_handle_request(tmcdreq_t *, int, char *, char *);
int tmcd_init(char *, struct in_addr *, int, int); int tmcd_init(tmcdreq_t *reqp, struct in_addr *, char *);
#endif /* _LIBTMCD_H_ */ #endif /* _LIBTMCD_H_ */
...@@ -780,12 +780,15 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp) ...@@ -780,12 +780,15 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp)
} }
} }
tmcd_init(NULL, &myipaddr, verbose, debug); reqp->verbose = verbose;
reqp->debug = debug;
tmcd_init(reqp, &myipaddr, NULL);
/* /*
* Map the ip to a nodeid. * Map the ip to a nodeid.
*/ */
if ((err = iptonodeid(client->sin_addr, reqp))) { if ((err = iptonodeid(reqp, client->sin_addr))) {
if (reqp->isvnode) { if (reqp->isvnode) {
error("No such vnode %s associated with %s\n", error("No such vnode %s associated with %s\n",
reqp->vnodeid, inet_ntoa(client->sin_addr)); reqp->vnodeid, inet_ntoa(client->sin_addr));
...@@ -826,13 +829,21 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp) ...@@ -826,13 +829,21 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp)
/* /*
* If the connection is not SSL, then it must be a local node. * If the connection is not SSL, then it must be a local node.
*/ */
if (reqp->isssl) { if (isssl) {
#if 0
if (tmcd_sslverify_client(reqp->nodeid, reqp->pclass, if (tmcd_sslverify_client(reqp->nodeid, reqp->pclass,
reqp->ptype, reqp->islocal)) { reqp->ptype, reqp->islocal)) {
error("%s: SSL verification failure\n", reqp->nodeid); error("%s: SSL verification failure\n", reqp->nodeid);
if (! redirect) if (! redirect)
goto skipit; goto skipit;
} }
#endif
if (tmcd_sslverify_client(NULL, NULL,
reqp->ptype, reqp->islocal)) {
error("%s: SSL verification failure\n", reqp->nodeid);
if (! redirect)
goto skipit;
}
} }
else if (reqp->iscontrol) { else if (reqp->iscontrol) {
error("%s: Control node connection without SSL!\n", error("%s: Control node connection without SSL!\n",
...@@ -881,14 +892,14 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp) ...@@ -881,14 +892,14 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp)
goto skipit; goto skipit;
*/ */
} }
else if (checkprivkey(client->sin_addr, privkey)) { else if (checkprivkey(reqp, client->sin_addr, privkey)) {
error("%s: privkey mismatch: %s!\n", error("%s: privkey mismatch: %s!\n",
reqp->nodeid, privkey); reqp->nodeid, privkey);
goto skipit; goto skipit;
} }
} }
execute: execute:
response = tmcd_handle_request(sock, bp, rdata, reqp); response = tmcd_handle_request(reqp, sock, bp, rdata);
skipit: skipit:
if (response) { if (response) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment