From f968d6110f2ddfac8a2dca2687ba6e4d57574ced Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 14 Aug 2002 05:43:05 +0000 Subject: [PATCH] added db passwd svn path=/trunk/boinc/; revision=325 --- db/db.h | 2 +- db/mysql_util.C | 24 ++---------------------- db/mysql_util.h | 2 +- sched/Makefile.in | 1 + sched/feeder.C | 2 +- sched/main.C | 2 +- tools/add.C | 2 +- tools/create_work.C | 2 +- 8 files changed, 9 insertions(+), 28 deletions(-) diff --git a/db/db.h b/db/db.h index 0b1419518f..c05c08abab 100644 --- a/db/db.h +++ b/db/db.h @@ -238,7 +238,7 @@ struct RESULT { int parse_from_client(FILE*); }; -extern int db_open(char*); +extern int db_open(char* dbname, char* passwd); extern int db_close(); extern void db_print_error(char*); extern int db_insert_id(); diff --git a/db/mysql_util.C b/db/mysql_util.C index 1ba6571878..4d73915964 100644 --- a/db/mysql_util.C +++ b/db/mysql_util.C @@ -24,7 +24,6 @@ #include #include #include -#include #include "mysql.h" #include "mysql_util.h" @@ -39,11 +38,10 @@ static MYSQL_ROW row; #define MAX_QUERY_LEN 8192 -int db_open(char* name) { - //assert(name!=NULL); +int db_open(char* dbname, char* password) { mp = mysql_init(0); if (!mp) return -1; - mp = mysql_real_connect(mp, 0, 0, "", name, 0, 0, 0); + mp = mysql_real_connect(mp, 0, 0, password, dbname, 0, 0, 0); if (!mp) return -1; return 0; } @@ -54,7 +52,6 @@ int db_close() { } void db_print_error(char* p) { - assert(p!=NULL); if (mp) { printf("
%s: Database error: %s\n", p, mysql_error(mp)); } @@ -62,7 +59,6 @@ void db_print_error(char* p) { // convert ' to \' in place void escape(char* field) { - assert(field!=NULL); char buf[MAX_QUERY_LEN]; char* q = buf, *p = field; while (*p) { @@ -80,7 +76,6 @@ void escape(char* field) { void unescape(char* p) { char* q; - assert(p!=NULL); while (1) { q = strstr(p, "\\'"); if (!q) break; @@ -90,13 +85,11 @@ void unescape(char* p) { // assumes ID is first static int* id(void* vp, int type) { - assert(vp!=NULL); return (int*) vp; } int db_new(void* vp, int type) { char buf[MAX_QUERY_LEN], sbuf[MAX_QUERY_LEN]; - assert(vp!=NULL); struct_to_str(vp, sbuf, type); sprintf(buf, "insert into %s set %s", table_name[type], sbuf); return mysql_query(mp, buf); @@ -118,7 +111,6 @@ int db_delete(int id, int type) { int db_lookup_id(int i, void* vp, int type) { char buf[MAX_QUERY_LEN]; - assert(vp!=NULL); sprintf(buf, "select * from %s where id=%d", table_name[type], i); mysql_query(mp, buf); rp = mysql_store_result(mp); @@ -131,8 +123,6 @@ int db_lookup_id(int i, void* vp, int type) { int db_lookup(void* vp, int type, char* clause) { char buf[MAX_QUERY_LEN]; - assert(vp!=NULL); - assert(clause!=NULL); sprintf(buf, "select * from %s where %s", table_name[type], clause); mysql_query(mp, buf); rp = mysql_store_result(mp); @@ -145,7 +135,6 @@ int db_lookup(void* vp, int type, char* clause) { int db_update(void* vp, int type) { char buf[MAX_QUERY_LEN], sbuf[MAX_QUERY_LEN]; - assert(vp!=NULL); struct_to_str(vp, sbuf, type); sprintf( buf, @@ -157,8 +146,6 @@ int db_update(void* vp, int type) { int db_enum(ENUM& e, void* p, int type, char* clause, int limit) { char buf[MAX_QUERY_LEN], buf2[256]; - //assert(p!=NULL); - //assert(clause!=NULL); if (!e.active) { e.active = 1; sprintf(buf, "select * from %s %s", table_name[type], clause?clause:""); @@ -183,8 +170,6 @@ int db_enum(ENUM& e, void* p, int type, char* clause, int limit) { int db_enum_field(ENUM& e, int type, char* field, char* clause) { char buf[MAX_QUERY_LEN]; - assert(field!=NULL); - assert(clause!=NULL); if (!e.active) { e.active = 1; sprintf(buf, "select %s from %s %s", field, table_name[type], clause); @@ -203,8 +188,6 @@ int db_enum_field(ENUM& e, int type, char* field, char* clause) { } int db_query_int(int* ip, char* query) { - assert(ip!=NULL); - assert(query!=NULL); mysql_query(mp, query); rp = mysql_store_result(mp); if (!rp) return -1; @@ -217,9 +200,6 @@ int db_query_int(int* ip, char* query) { int db_count(int* np, char* what, int type, char* clause) { char buf[MAX_QUERY_LEN]; - assert(np!=NULL); - assert(what!=NULL); - assert(clause!=NULL); sprintf(buf, "select count(%s) from %s %s", what, table_name[type], clause); return db_query_int(np, buf); } diff --git a/db/mysql_util.h b/db/mysql_util.h index 059cd59b22..86af276891 100644 --- a/db/mysql_util.h +++ b/db/mysql_util.h @@ -24,7 +24,7 @@ struct ENUM { MYSQL_RES *rp; }; -extern int db_open(char*); +extern int db_open(char* dbname, char* password); extern int db_close(); extern void db_print_error(); diff --git a/sched/Makefile.in b/sched/Makefile.in index e0995aca2f..8eafafbd57 100644 --- a/sched/Makefile.in +++ b/sched/Makefile.in @@ -12,6 +12,7 @@ CFLAGS = -g -Wall @DEFS@ \ -I@top_srcdir@/lib \ -I@top_srcdir@/tools \ -DBOINC_DB_NAME=\"$(BOINC_DB_NAME)\" \ + -DBOINC_DB_PASSWD=\"$(BOINC_DB_PASSWD)\" \ -DBOINC_KEY=$(BOINC_KEY) \ -DBOINC_KEY_DIR=\"$(BOINC_KEY_DIR)\" \ -DBOINC_UPLOAD_DIR=\"$(BOINC_UPLOAD_DIR)\" \ diff --git a/sched/feeder.C b/sched/feeder.C index 1a5f02b39d..776428bd03 100644 --- a/sched/feeder.C +++ b/sched/feeder.C @@ -191,7 +191,7 @@ int main(int argc, char** argv) { } ssp = (SCHED_SHMEM*)p; ssp->init(); - retval = db_open(getenv("BOINC_DB_NAME")); + retval = db_open(getenv("BOINC_DB_NAME"), getenv("BOINC_DB_PASSWD")); if (retval) { fprintf(stderr, "feeder: db_open: %d\n", retval); exit(1); diff --git a/sched/main.C b/sched/main.C index b5a36540d9..4cf1274a3e 100644 --- a/sched/main.C +++ b/sched/main.C @@ -84,7 +84,7 @@ int main() { exit(1); } //fprintf(stderr, "got ready flag\n"); - retval = db_open(BOINC_DB_NAME); + retval = db_open(BOINC_DB_NAME, BOINC_DB_PASSWD); if (retval) { exit(return_error("BOINC scheduler - Compiled by BOINC_USER: can't open database")); } diff --git a/tools/add.C b/tools/add.C index ff7bae2c84..84687926a1 100644 --- a/tools/add.C +++ b/tools/add.C @@ -253,7 +253,7 @@ void add_user() { int main(int argc, char** argv) { int i, retval; - retval = db_open(getenv("BOINC_DB_NAME")); + retval = db_open(getenv("BOINC_DB_NAME"), getenv("BOINC_DB_PASSWD")); if (retval) { printf("can't open DB %s\n", getenv("BOINC_DB_NAME")); } diff --git a/tools/create_work.C b/tools/create_work.C index d5d86022e9..3dea1ac699 100644 --- a/tools/create_work.C +++ b/tools/create_work.C @@ -65,7 +65,7 @@ int main(int argc, char** argv) { printf("must define BOINC_DOWNLOAD_DIR"); exit(1); } - if (db_open(getenv("BOINC_DB_NAME"))) { + if (db_open(getenv("BOINC_DB_NAME"), getenv("BOINC_DB_PASSWD"))) { printf( "Error opening database.\n" ); exit(0); }