bambi6-service-postit

Simple Note-Taking A/D Service for BambiCTF6 in 2021
git clone https://git.sinitax.com/sinitax/bambi6-service-postit
Log | Files | Refs | README | LICENSE | sfeed.txt

gendb.c (931B)


      1#include <stdlib.h>
      2#include <stdio.h>
      3
      4#include "sqlite3.h"
      5
      6#include "util.h"
      7
      8static sqlite3 *db = NULL;
      9
     10int
     11main(int argc, const char **argv)
     12{
     13	const char *dbpath, *sql;
     14	char *err_msg = NULL;
     15	int status;
     16
     17	dbpath = "db.sqlite3";
     18	if (argc > 1) dbpath = argv[1];
     19
     20	status = sqlite3_open(dbpath, &db);
     21	ASSERTV(status == SQLITE_OK, "Cannot access database: %s",
     22		sqlite3_errmsg(db));
     23
     24	sql = "CREATE TABLE IF NOT EXISTS users(uid INTEGER PRIMARY KEY,"
     25		" name TEXT, mod TEXT, exp TEXT, creat INTEGER);";
     26	status = sqlite3_exec(db, sql, 0, 0, NULL);
     27	ASSERTV(status == SQLITE_OK, "Failed to create users table: %s",
     28		sqlite3_errmsg(db));
     29
     30	sql = "CREATE TABLE IF NOT EXISTS posts(pid INTEGER PRIMARY KEY,"
     31		" uid INTEGER SECONDARY KEY, text TEXT, creat INTEGER);";
     32	status = sqlite3_exec(db, sql, 0, 0, NULL);
     33	ASSERTV(status == SQLITE_OK, "Failed to create posts table: %s",
     34		sqlite3_errmsg(db));
     35
     36	sqlite3_close(db);
     37}