diff --git a/mysql-dbadm.c b/mysql-dbadm.c index d1846f5..1a087eb 100644 --- a/mysql-dbadm.c +++ b/mysql-dbadm.c @@ -1,5 +1,5 @@ /* - * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.9 2003-04-03 22:37:44 lkarsten Exp $ + * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.10 2003-04-07 16:21:36 lkarsten Exp $ * * mysql-dbadm.c * @@ -123,6 +123,7 @@ list(MYSQL *pmysql) char **dblist; int i, counter; struct passwd *p; + char *escaped_user; p = getpwuid(getuid()); if (!p) @@ -139,15 +140,52 @@ list(MYSQL *pmysql) usr_groups = get_group_names(&numgroups); cp = usr_groups; while (*cp) { +// ettersom _ og % er wildcards i sql, må vi escape +// eventuelle slike i gruppenavnet. "kall_s" f.eks, bør +// bli til "kall\_s" før det går til databasen. + int i, j; + char* user_start; + char* cp_kopi; + + cp_kopi = *cp; + + escaped_user = (char*)malloc(64 * sizeof(char)); + user_start = escaped_user; + if (*cp == NULL) break; - wild = malloc(strlen(*cp)+3); - sprintf(wild, "%s\\_%%", *cp); + printf("cp er %s\n", *cp); + + for(i=j=0; ipw_name) + 3); - sprintf(wild, "%s_%%", p->pw_name); + sprintf(wild, "%s\\_%%", p->pw_name); +#ifdef DEBUG + printf("dbadm: wildcard: '%s'\n", wild); +#endif res = mysql_list_dbs(pmysql, wild); rows = mysql_num_rows(res);