2001-11-25 01:41:16 +01:00
|
|
|
/*
|
2007-02-27 15:10:08 +01:00
|
|
|
* @($) $Id: pwfile.c,v 1.3 2007-02-27 14:10:08 geirha Exp $
|
2001-11-25 01:41:16 +01:00
|
|
|
*
|
|
|
|
* functions for parsing the config file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2007-02-27 15:10:08 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-11-25 01:41:16 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include "mysql-admutils.h"
|
2018-10-26 16:53:47 +02:00
|
|
|
// #include "pwyacc.h"
|
|
|
|
#include "toml.h"
|
2001-11-25 01:41:16 +01:00
|
|
|
|
|
|
|
/* defaults for configurable values */
|
|
|
|
const char* db_user = "root";
|
2018-10-25 13:52:19 +02:00
|
|
|
const char* db_server = "mysql.stud.ntnu.no";
|
2018-10-26 16:53:47 +02:00
|
|
|
const char* db_passwd = NULL ;
|
2001-11-25 01:41:16 +01:00
|
|
|
const char* db_name = "mysql";
|
|
|
|
|
|
|
|
extern int yyparse(void);
|
|
|
|
extern FILE *yyin;
|
|
|
|
|
|
|
|
int config_line = 1;
|
|
|
|
|
2018-10-26 16:53:47 +02:00
|
|
|
FILE* fp;
|
|
|
|
toml_table_t* conf;
|
|
|
|
toml_table_t* server;
|
|
|
|
const char* raw;
|
|
|
|
char* password;
|
|
|
|
char errbuf[200];
|
2001-11-25 01:41:16 +01:00
|
|
|
|
2018-10-26 16:53:47 +02:00
|
|
|
static char *tomlfile = SYSCONFDIR "/mysql-admutils.toml";
|
2001-11-25 01:41:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
int
|
2018-10-26 16:53:47 +02:00
|
|
|
read_toml_file(void)
|
2001-11-25 01:41:16 +01:00
|
|
|
{
|
2018-10-26 16:53:47 +02:00
|
|
|
if (0 == (fp = fopen(tomlfile, "r"))) {
|
|
|
|
perror("fopen");
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-25 01:41:16 +01:00
|
|
|
|
2018-10-26 16:53:47 +02:00
|
|
|
conf = toml_parse_file(fp, errbuf, sizeof(errbuf));
|
|
|
|
fclose(fp);
|
|
|
|
if (0 == conf) {
|
|
|
|
fprintf(stderr, "ERROR: %s\n", errbuf);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-25 01:41:16 +01:00
|
|
|
|
2018-10-26 16:53:47 +02:00
|
|
|
if (0 == (server = toml_table_in(conf, "server"))) {
|
|
|
|
fprintf(stderr, "ERROR: missing [server]\n");
|
|
|
|
toml_free(conf);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-25 01:41:16 +01:00
|
|
|
|
2018-10-26 16:53:47 +02:00
|
|
|
if (0 == (raw = toml_raw_in(server, "password"))) {
|
|
|
|
fprintf(stderr, "ERROR: missing 'password' in [server]\n");
|
|
|
|
toml_free(conf);
|
|
|
|
exit(1);
|
2001-11-25 01:41:16 +01:00
|
|
|
}
|
2018-10-26 16:53:47 +02:00
|
|
|
if (toml_rtos(raw, &password)) {
|
|
|
|
fprintf(stderr, "ERROR: bad value in 'host'\n");
|
|
|
|
toml_free(conf);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
toml_free(conf);
|
|
|
|
|
|
|
|
db_passwd = password;
|
|
|
|
|
|
|
|
|
|
|
|
return db_passwd;
|
|
|
|
|
|
|
|
free(password);
|
|
|
|
|
2001-11-25 01:41:16 +01:00
|
|
|
}
|