Validate user names against allowed chars

This commit is contained in:
2012-12-11 14:24:07 +00:00
parent 3c39c277bd
commit c2c0659bc8
4 changed files with 43 additions and 21 deletions

View File

@@ -250,3 +250,17 @@ char *strmov(char *dest, const char *src) {
;
return dest-1;
}
/* New database and user names may only use these characters in their
identifier */
const char name_validchars[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
/* Returns true if dbname contains only characters in name_validchars. */
int name_isclean(char* name) {
int reallen, cleanlen;
reallen = strlen(name);
cleanlen = strspn(name, name_validchars);
return (reallen == cleanlen);
}