mysql-dbadm sanitychecks groupnames. configline updated with diff

for static linking.
y
This commit is contained in:
Lasse Karstensen 2003-04-08 18:31:53 +00:00
parent 4148dda169
commit 05db606260
2 changed files with 66 additions and 40 deletions

View File

@ -5,6 +5,40 @@ vanlig, p
vi burde kanskje komplisere med libmysqlclient statisk, vi burde kanskje komplisere med libmysqlclient statisk,
sånn at vi slipper avhengigheter mot en spesiell rpmpakke. sånn at vi slipper avhengigheter mot en spesiell rpmpakke.
$Id: configline,v 1.1 2003-04-07 16:23:25 lkarsten Exp $
elefant:~/mysql-admutils$ diff -u ../Makefile.org Makefile
--- ../Makefile.org Tue Apr 8 20:20:00 2003
+++ Makefile Tue Apr 8 20:22:27 2003
@@ -62,8 +62,8 @@
LEX = flex
MAKEINFO = makeinfo
MYSQL_INCLUDE = -I/store/include/mysql
-MYSQL_LFLAGS = -L/store/lib/mysql
-MYSQL_LIBS = -lmysqlclient
+MYSQL_LFLAGS =
+MYSQL_LIBS =
PACKAGE = mysql-admutils
SYSCONFDIR =
VERSION = 0.43
@@ -76,8 +76,8 @@
BUILT_SOURCES = pwyacc.c pwyacc.h pwlex.c
YFLAGS = -d
INCLUDES = -I/store/include/mysql -DSYSCONFDIR=\"$(sysconfdir)\"
-LDADD = -lmysqlclient -lfl
-LDFLAGS = -L/store/lib/mysql
+LDADD = /store/lib/mysql/libmysqlclient.a -lfl
+LDFLAGS =
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = config.h
$Id: configline,v 1.2 2003-04-08 18:31:53 lkarsten Exp $
$Source: /tmp/cvs/mysql-admutils/configline,v $ $Source: /tmp/cvs/mysql-admutils/configline,v $

View File

@ -1,5 +1,5 @@
/* /*
* @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.10 2003-04-07 16:21:36 lkarsten Exp $ * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.11 2003-04-08 18:31:53 lkarsten Exp $
* *
* mysql-dbadm.c * mysql-dbadm.c
* *
@ -123,7 +123,10 @@ list(MYSQL *pmysql)
char **dblist; char **dblist;
int i, counter; int i, counter;
struct passwd *p; struct passwd *p;
char *escaped_user;
// variabler som brukes til å escape gruppenavnet til mysqlvennlig format.
char escaped_user[64];
char *cp_kopi;
p = getpwuid(getuid()); p = getpwuid(getuid());
if (!p) if (!p)
@ -139,48 +142,30 @@ 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) { // itererer over alle grupper en person er med i
// 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;
#ifdef DEBUG
printf("cp er %s\n", *cp); printf("cp er %s\n", *cp);
#endif
for(i=j=0; i<strlen(*cp); i++){ escaped_user[0] = '\0';
cp_kopi=*cp;
printf("%c.\n", *cp[i]); // itererer over bokstavene i gruppenavn, og escaper spesialtegn.
// unntak, typisk _ eller % for(i=0; i<=strlen(cp_kopi); i++) {
if ((*cp[i] == '_') || (*cp[i] == '%')) { // hvis % _ , så skriv \ og så tegn
char foo; if ((cp_kopi[i] == '_') || (cp_kopi[i] == '%')) {
foo = (char)'\\'; strcat(escaped_user, "\\");
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);
escaped_user[strlen(escaped_user) + 1] = '\0';
escaped_user[strlen(escaped_user)] = cp_kopi[i];
} // for
wild = malloc(strlen(escaped_user)+3);
sprintf(wild, "%s\\_%%", escaped_user);
#ifdef DEBUG #ifdef DEBUG
printf("dbadm: wildcard: '%s'\n", wild); printf("dbadm: wildcard: '%s'\n", wild);
@ -202,7 +187,6 @@ list(MYSQL *pmysql)
free(wild); free(wild);
free(escaped_user);
cp++; cp++;
} }
@ -303,7 +287,8 @@ editperm(MYSQL *pmysql, const char *db)
int lines; /* number of grant lines processed */ int lines; /* number of grant lines processed */
int i; /* iterate through lines[] */ int i; /* iterate through lines[] */
mktemp(fn); mkstemp(fn);
if (strcmp(fn, "") == 0) if (strcmp(fn, "") == 0)
return dberror(NULL, "Cannot create a unique temporary file name."); return dberror(NULL, "Cannot create a unique temporary file name.");
@ -434,6 +419,13 @@ main(int argc, char *argv[])
if (argc < 2) if (argc < 2)
return wrong_use(NULL); return wrong_use(NULL);
#ifdef DEBUG
printf("NB NB NB: denne versjonen av programmet er kompilert med -DDEBUG, og\n");
printf("kan komme til å skrive ut ekstra informasjon. Dette er ikke farlig,\n");
printf("og programmet bør virke som vanlig.\n");
#endif
/* check that the supplied command is valid */ /* check that the supplied command is valid */
if (strcmp(argv[1], "create") == 0) if (strcmp(argv[1], "create") == 0)