]> foleosoft.com Git - RosadoAPI.git/commitdiff
Sun Jan 19 10:02:51 PM EST 2025
authorserver <[email protected]>
Mon, 20 Jan 2025 03:02:51 +0000 (22:02 -0500)
committerserver <[email protected]>
Mon, 20 Jan 2025 03:02:51 +0000 (22:02 -0500)
src/main.c

index 82bd2e89c37b5b633de359f6b449e6b34c568a5f..91f624196b82e4cdacc9ad00d4cf176170f42d1a 100644 (file)
@@ -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;