pass på, broken state!

This commit is contained in:
Lasse Karstensen 2003-04-07 16:21:36 +00:00
parent 10c81e04b5
commit 49241f6e03
1 changed files with 48 additions and 6 deletions

View File

@ -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 * mysql-dbadm.c
* *
@ -123,6 +123,7 @@ list(MYSQL *pmysql)
char **dblist; char **dblist;
int i, counter; int i, counter;
struct passwd *p; struct passwd *p;
char *escaped_user;
p = getpwuid(getuid()); p = getpwuid(getuid());
if (!p) if (!p)
@ -139,15 +140,52 @@ list(MYSQL *pmysql)
usr_groups = get_group_names(&numgroups); usr_groups = get_group_names(&numgroups);
cp = usr_groups; cp = usr_groups;
while (*cp) { 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) if (*cp == NULL)
break; break;
wild = malloc(strlen(*cp)+3); printf("cp er %s\n", *cp);
sprintf(wild, "%s\\_%%", *cp);
for(i=j=0; i<strlen(*cp); i++){
printf("%c.\n", *cp[i]);
// unntak, typisk _ eller %
if ((*cp[i] == '_') || (*cp[i] == '%')) {
char foo;
foo = (char)'\\';
escaped_user[j] = foo;
j++;
printf("%c.....\n", escaped_user);
}
// vanlig kopiering
escaped_user[j] = cp[i];
//strncpy(&escaped_user[j], &*cp[i], 1);
j++;
} // while
printf("escaped_user er %s\n", escaped_user);
wild = malloc(strlen(user_start)+3);
sprintf(wild, "%s\\_%%", user_start);
#ifdef DEBUG #ifdef DEBUG
printf("dbadm: wildcard: %s\n", wild); printf("dbadm: wildcard: '%s'\n", wild);
#endif #endif
res = mysql_list_dbs(pmysql, wild); res = mysql_list_dbs(pmysql, wild);
rows = mysql_num_rows(res); rows = mysql_num_rows(res);
@ -163,12 +201,16 @@ list(MYSQL *pmysql)
} }
free(wild); free(wild);
free(escaped_user);
cp++; cp++;
} }
wild = malloc(strlen(p->pw_name) + 3); wild = malloc(strlen(p->pw_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); res = mysql_list_dbs(pmysql, wild);
rows = mysql_num_rows(res); rows = mysql_num_rows(res);