La inn ein argumentsjekk av databasenamn når vi lagar databaser. Det er masse

cruft i databasekatalogen til mysql.stud - databasenamn med space, newline,
osv... =)
This commit is contained in:
Anders Morken 2006-07-05 09:00:52 +00:00
parent 83dd083eec
commit 2191acfd78
1 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* /*
* @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.13 2005-06-27 10:13:01 knuta Exp $ * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.14 2006-07-05 09:00:52 andersmo Exp $
* *
* mysql-dbadm.c * mysql-dbadm.c
* *
@ -18,6 +18,18 @@
#include <unistd.h> #include <unistd.h>
#include "mysql-admutils.h" #include "mysql-admutils.h"
/* New database names may only use these characters in their identifier */
const char dbname_validchars[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
/* Returns true if dbname contains only characters in dbname_validchars. */
int dbname_isclean(char* dbname) {
int reallen, cleanlen;
reallen = strlen(dbname);
cleanlen = strspn(dbname, dbname_validchars);
return (reallen == cleanlen);
}
char * char *
strchr_whitespace(const char *s) strchr_whitespace(const char *s)
{ {
@ -500,7 +512,13 @@ main(int argc, char *argv[])
switch (command) { switch (command) {
case c_create: case c_create:
// We only check newly created databases. Many old ("unclean") databases are still in use.
if(dbname_isclean(db)) {
create(&mysql, db); create(&mysql, db);
} else {
dberror(NULL, "Database name '%s' contains invalid characters.\n"
"Only A-Z, a-z, 0-9, _ (underscore) and - (dash) permitted. Skipping.", db);
}
break; break;
case c_drop: case c_drop:
drop(&mysql, db); drop(&mysql, db);