Fjerner filer som ikke lenger trengs

This commit is contained in:
Aslak Raanes 2018-10-26 16:53:47 +02:00
parent 2b815b30d3
commit ef4add6a89
7 changed files with 53 additions and 160 deletions

View File

@ -1,8 +1,7 @@
bin_PROGRAMS = mysql-dbadm mysql-useradm bin_PROGRAMS = mysql-dbadm mysql-useradm
mysql_admutils_SOURCE = common.c mysql-admutils.h pwyacc.y pwlex.l pwfile.c mysql_admutils_SOURCE = common.c mysql-admutils.h toml.c pwfile.c
mysql_dbadm_SOURCES = mysql-dbadm.c $(mysql_admutils_SOURCE) mysql_dbadm_SOURCES = mysql-dbadm.c $(mysql_admutils_SOURCE)
mysql_useradm_SOURCES = mysql-useradm.c $(mysql_admutils_SOURCE) mysql_useradm_SOURCES = mysql-useradm.c $(mysql_admutils_SOURCE)
BUILT_SOURCES = pwyacc.c pwyacc.h pwlex.c
AM_YFLAGS = -d AM_YFLAGS = -d
AM_CPPFLAGS = @MYSQL_INCLUDE@ -DSYSCONFDIR=\"$(sysconfdir)\" AM_CPPFLAGS = @MYSQL_INCLUDE@ -DSYSCONFDIR=\"$(sysconfdir)\"
LDADD = @MYSQL_LIBS@ @LEXLIB@ LDADD = @MYSQL_LIBS@ @LEXLIB@

View File

@ -14,6 +14,7 @@ extern const char *db_user;
extern const char *db_passwd; extern const char *db_passwd;
extern const char *db_name; extern const char *db_name;
extern int extern int
wrong_use(char *format, ...); wrong_use(char *format, ...);
@ -31,7 +32,7 @@ extern int
version(void); version(void);
extern int extern int
read_config_file(void); read_toml_file(void);
/* same as strcpy, but returns a pointer to the end of dest instead of start */ /* same as strcpy, but returns a pointer to the end of dest instead of start */
extern char *strmov(char *, const char *); extern char *strmov(char *, const char *);

View File

@ -619,7 +619,7 @@ main(int argc, char *argv[])
if ((command != c_show) && (argc < 3)) if ((command != c_show) && (argc < 3))
return wrong_use(NULL); return wrong_use(NULL);
/* read_config_file(); */ read_toml_file();
/* connect to the database server and select the mysql database */ /* connect to the database server and select the mysql database */
if (!mysql_real_connect(&mysql, db_server, db_user, db_passwd, db_name, 0, NULL, 0)) if (!mysql_real_connect(&mysql, db_server, db_user, db_passwd, db_name, 0, NULL, 0))

View File

@ -278,6 +278,7 @@ main(int argc, char *argv[])
return wrong_use(NULL); return wrong_use(NULL);
/* read_config_file(); */ /* read_config_file(); */
read_toml_file();
/* connect to the database server and select the mysql database */ /* connect to the database server and select the mysql database */
if (!mysql_real_connect(&mysql, db_server, db_user, db_passwd, db_name, 0, NULL, 0)) if (!mysql_real_connect(&mysql, db_server, db_user, db_passwd, db_name, 0, NULL, 0))

120
pwfile.c
View File

@ -12,15 +12,13 @@
#include <unistd.h> #include <unistd.h>
#include <sys/resource.h> #include <sys/resource.h>
#include "mysql-admutils.h" #include "mysql-admutils.h"
#include "pwyacc.h" // #include "pwyacc.h"
#include "toml.h"
/* the MySQL maximum */
#define MAXPWCHARS 16
/* defaults for configurable values */ /* defaults for configurable values */
const char* db_user = "root"; const char* db_user = "root";
const char* db_server = "mysql.stud.ntnu.no"; const char* db_server = "mysql.stud.ntnu.no";
const char* db_passwd = MYSQLPW ; const char* db_passwd = NULL ;
const char* db_name = "mysql"; const char* db_name = "mysql";
extern int yyparse(void); extern int yyparse(void);
@ -28,81 +26,55 @@ extern FILE *yyin;
int config_line = 1; int config_line = 1;
static FILE *pwfile; FILE* fp;
static char *filename = SYSCONFDIR "/mysql-admutils.conf"; toml_table_t* conf;
toml_table_t* server;
const char* raw;
char* password;
char errbuf[200];
int static char *tomlfile = SYSCONFDIR "/mysql-admutils.toml";
read_config_file(void)
{
struct rlimit rlim;
int rc; /* return code */
/* to stop the user from obtaining the password from a core dump. */
if (getrlimit(RLIMIT_CORE, &rlim) == -1) {
perror("getrlimit");
exit(1);
}
rlim.rlim_max = 0;
if (setrlimit(RLIMIT_CORE, &rlim) == -1) {
perror("setrlimit");
exit(1);
}
pwfile = fopen(filename, "r");
if (!pwfile) {
fatal_error("cannot open configuration file %s", filename);
exit(1);
}
/* we don't need to be SUID anymore. */
if (seteuid(getuid()) != 0)
perror("seteuid");
yyin = pwfile;
rc = yyparse();
fclose(pwfile);
return rc;
}
int int
yywrap(void) read_toml_file(void)
{ {
return 1; if (0 == (fp = fopen(tomlfile, "r"))) {
} perror("fopen");
int
yyerror(const char *msg)
{
fprintf(stderr, "%s:%d: %s\n", filename, config_line, msg);
return 0;
}
int
config_set_string_var(int var, const char *value)
{
assert(value);
switch (var) {
case USER:
db_user = value;
break;
case HOST:
db_server = value;
break;
case PASSWORD:
if (strlen(value) > MAXPWCHARS) {
fprintf(stderr, "%s:%d: password is too long (%d chars > %d chars)\n",
filename, config_line, strlen(value), MAXPWCHARS);
fclose(pwfile);
exit(1); exit(1);
} }
db_passwd = value;
break; conf = toml_parse_file(fp, errbuf, sizeof(errbuf));
default: fclose(fp);
assert(!"We should never get here."); if (0 == conf) {
fprintf(stderr, "ERROR: %s\n", errbuf);
exit(1);
} }
return 0;
if (0 == (server = toml_table_in(conf, "server"))) {
fprintf(stderr, "ERROR: missing [server]\n");
toml_free(conf);
exit(1);
}
if (0 == (raw = toml_raw_in(server, "password"))) {
fprintf(stderr, "ERROR: missing 'password' in [server]\n");
toml_free(conf);
exit(1);
}
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);
} }

47
pwlex.l
View File

@ -1,47 +0,0 @@
/*
* @(#) $Id: pwlex.l,v 1.1.1.1 2001-11-25 00:41:16 lkarsten Exp $
*
* lex source for the configuration file
*
*/
%{
#include <stdio.h>
#include <string.h>
#include "pwyacc.h"
extern int config_line;
extern int yylval;
%}
%%
#.*\n config_line++;
set { yylval = SET; return(SET); }
host { yylval = HOST; return(HOST); };
user { yylval = USER; return(USER); };
password { yylval = PASSWORD; return(PASSWORD); }
\"[^"]*\" {
if (yytext[yyleng - 1] == '\\')
yymore();
else
yytext[yyleng - 1] = '\0';
yylval = (int)strdup(yytext + 1);
return(STRING);
};
; return(';');
[^ \t\n\;]* {
yylval = (int)strdup(yytext);
return(STRING);
}
[ \t] ;
\n config_line++;
%%

View File

@ -1,33 +0,0 @@
/*
* @(#) $Id: pwyacc.y,v 1.1.1.1 2001-11-25 00:41:16 lkarsten Exp $
*
* yacc source for parsing the configuration file
*
*/
%{
int yyerror(const char *msg);
int yylex(void);
int config_set_string_var(int var, const char *value);
%}
%token SET HOST USER PASSWORD STRING
%%
input: ;
input: statement input ;
statement: SET variable STRING ';'
{
$$ = config_set_string_var($2, (const char *)$3);
}
;
variable: USER | PASSWORD | HOST
{ $$ = $1; }
;
%%