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
*
@ -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; 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
printf("dbadm: wildcard: %s\n", wild);
printf("dbadm: wildcard: '%s'\n", wild);
#endif
res = mysql_list_dbs(pmysql, wild);
rows = mysql_num_rows(res);
@ -163,12 +201,16 @@ list(MYSQL *pmysql)
}
free(wild);
free(wild);
free(escaped_user);
cp++;
}
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);
rows = mysql_num_rows(res);