From: server Date: Mon, 20 Jan 2025 03:02:51 +0000 (-0500) Subject: Sun Jan 19 10:02:51 PM EST 2025 X-Git-Url: http://www.foleosoft.com/?a=commitdiff_plain;h=5a4a318bb4e9e0f1556511cd025a03013d1ed90b;p=RosadoAPI.git Sun Jan 19 10:02:51 PM EST 2025 --- diff --git a/src/main.c b/src/main.c index 82bd2e8..91f6241 100644 --- a/src/main.c +++ b/src/main.c @@ -8,29 +8,22 @@ uint8_t HOSTNAME[1024]; uint8_t HOSTNAME_I[1024]; +uint8_t SQLPASS[1024]; //grabs auth info from the database uint8_t* getDatabaseInfo(uint8_t type, uint8_t* a, uint8_t* b, uint8_t* c) { uint8_t* ret = NULL; - MYSQL *conn; - MYSQL_RES *res; - MYSQL_ROW row; - conn = mysql_init(NULL); - FILE *f = fopen("/usr/share/estous/password", "r"); - if (!f) + MYSQL *conn; + MYSQL_RES *res; + MYSQL_ROW row; + conn = mysql_init(NULL); + + if (!mysql_real_connect(conn, "localhost", HOSTNAME, SQLPASS, "RosadoAPI", 0, NULL, 0)) { - fprintf(stderr, "Could not open /usr/share/estousapi/password\n"); - exit(1); + fprintf(stderr, "%s\n", mysql_error(conn)); + return NULL; } - char* p = malloc(0); - int c; - while ( (c = fgetc(f)) != EOF) - - if (!mysql_real_connect(conn, "localhost", HOSTNAME, "", "APIService", 0, NULL, 0)) { - fprintf(stderr, "%s\n", mysql_error(conn)); - return NULL; - } if (type == 1) { @@ -93,7 +86,7 @@ uint8_t* runService(uint8_t* service_name, uint8_t* service_data, uint32_t* serv } } - uint8_t template[] = "/tmp/apiserviceXXXXXX"; + uint8_t template[] = "/tmp/rosadoapiXXXXXX"; int8_t fd = mkstemp(template); if (fd == -1) { @@ -388,6 +381,25 @@ void *handleRequest(void *vargp) httpEnd(session_fd); } +void get_sqlpass() +{ + FILE *f = fopen("/usr/share/rosadoapi/password", "r"); + if (!f) + { + fprintf(stderr, "RosadoAPI: Could not access /usr/share/rosadoapi/password\n"); + exit(1); + } + int c; + int plen = 0; + while ( (c = fgetc(f)) != EOF) + { + if (c == '\n' || c == '\r' || c == ' ') break; + SQLPASS[plen++] = c; + if (plen == sizeof(SQLPASS) - 2) break; + } + SQLPASS[plen] = 0; +} + void get_hostname() { for (uint8_t i = 0; i <= 1; i++) @@ -424,7 +436,8 @@ void get_hostname() void main() { get_hostname(); - + get_sqlpass(); + MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; @@ -433,12 +446,12 @@ void main() conn = mysql_init(NULL); // Connect to the database - if (!mysql_real_connect(conn, "localhost", HOSTNAME, "PAAAAAAAAAAAA", "APIService", 0, NULL, 0)) { + if (!mysql_real_connect(conn, "localhost", HOSTNAME, SQLPASS, "RosadoAPI", 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); return; } - if (mysql_query(conn, "select 1 from information_schema.tables where table_schema='APIService' and table_name='AuthInfo' limit 1;")) + if (mysql_query(conn, "select 1 from information_schema.tables where table_schema='RosadoAPI' and table_name='AuthInfo' limit 1;")) { fprintf(stderr, "%s\n", mysql_error(conn)); return; @@ -455,7 +468,7 @@ void main() } mysql_free_result(res); - if (mysql_query(conn, "select 1 from information_schema.tables where table_schema='APIService' and table_name='ServiceInfo' limit 1;")) + if (mysql_query(conn, "select 1 from information_schema.tables where table_schema='RosadoAPI' and table_name='ServiceInfo' limit 1;")) { fprintf(stderr, "%s\n", mysql_error(conn)); return;