beautifisering (2-space-indent), og tetting av minnehull

This commit is contained in:
Geir Hauge 2006-08-15 11:51:59 +00:00
parent 2e1453ceba
commit 5a1f013a31
2 changed files with 218 additions and 220 deletions

View File

@ -1,5 +1,5 @@
/*
* @(#) $Header: /tmp/cvs/mysql-admutils/common.c,v 1.7 2006-08-15 10:32:42 geirha Exp $
* @(#) $Header: /tmp/cvs/mysql-admutils/common.c,v 1.8 2006-08-15 11:51:58 geirha Exp $
*
* functions used by mysql-dbadm.c and mysql-useradm.c
*
@ -22,7 +22,7 @@
char *program_name;
static char *rcsheader = "@(#) " PACKAGE " " VERSION " orakel@ntnu.no $Header: /tmp/cvs/mysql-admutils/common.c,v 1.7 2006-08-15 10:32:42 geirha Exp $";
static char *rcsheader = "@(#) " PACKAGE " " VERSION " orakel@ntnu.no $Header: /tmp/cvs/mysql-admutils/common.c,v 1.8 2006-08-15 11:51:58 geirha Exp $";
int
@ -38,8 +38,7 @@ wrong_use(char *format, ...)
{
va_list ap;
if (format)
{
if (format) {
fprintf(stderr, "%s: ", program_name);
va_start(ap, format);
vfprintf(stderr, format, ap);
@ -66,8 +65,7 @@ dberror(MYSQL *pmysql, char *format, ...)
va_end(ap);
fprintf(stderr, "\n");
if (pmysql)
{
if (pmysql) {
errmsg = mysql_error(pmysql);
if ((errmsg) && (strcmp(errmsg, "") != 0))
fprintf(stderr, "mysql: %s\n", errmsg);
@ -102,8 +100,7 @@ owner(char *name)
struct passwd *p;
p = getpwuid(getuid());
if (!p)
{
if (!p) {
dberror(NULL, "Failed to look up your UNIX username.");
exit(1);
}
@ -182,9 +179,10 @@ member(char *gr) {
printf("You have access to '%s'\n", gr);
#endif
return 1; /* OK */
} else
} else {
*g->gr_mem++;
}
}
#if DEBUG
printf("You have no access to '%s'\n", gr);
#endif

View File

@ -1,5 +1,5 @@
/*
* @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.15 2006-08-15 10:32:42 geirha Exp $
* @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.16 2006-08-15 11:51:59 geirha Exp $
*
* mysql-dbadm.c
*
@ -56,9 +56,7 @@ strtok_whitespace(char *s)
if (cp == NULL)
return r;
while ((*cp == ' ') || (*cp == '\t'))
{
*cp++ = '\0';
}
return r;
}
@ -154,13 +152,12 @@ list(MYSQL *pmysql)
int i, counter;
struct passwd *p;
// variabler som brukes til å escape gruppenavnet til mysqlvennlig format.
// variabler som brukes til å escape gruppenavnet til mysqlvennlig format.
char escaped_user[64];
char *cp_kopi;
p = getpwuid(getuid());
if (!p)
{
if (!p) {
dberror(NULL, "Failed to lookup your UNIX username.");
exit(1);
}
@ -209,14 +206,17 @@ list(MYSQL *pmysql)
dblist = realloc(dblist, (numgroupdbs+2) * sizeof(char *));
for (i = 0; i < rows; i++)
for (i = 0; i < rows; i++) {
if ((row = mysql_fetch_row(res))) {
dblist[counter++] = strdup(row[0]);
}
}
}
free(wild);
free(res);
free(cp_kopi);
cp++;
}
@ -230,18 +230,17 @@ list(MYSQL *pmysql)
rows = mysql_num_rows(res);
dblist = realloc(dblist, (numgroupdbs+rows+2) * sizeof(char *));
if (!dblist)
{
if (!dblist) {
dberror(NULL, "Out of memory.\n");
free(wild);
return NULL;
}
for (i = 0; i < rows; i++)
if ((row = mysql_fetch_row(res)))
{
for (i = 0; i < rows; i++) {
if ((row = mysql_fetch_row(res))) {
dblist[counter++] = strdup(row[0]);
}
}
res = mysql_list_dbs(pmysql, p->pw_name);
rows = mysql_num_rows(res);
@ -250,6 +249,8 @@ list(MYSQL *pmysql)
dblist[counter] = NULL;
free(wild);
free(usr_groups);
return dblist;
}
@ -276,13 +277,14 @@ writeperm(FILE *f, MYSQL *pmysql, const char *db)
if (rows == 0)
fprintf(f, "# (no permissions currently granted to any users)\n");
else
for (i = 0; i < rows; i++)
{
else {
for (i = 0; i < rows; i++) {
row = mysql_fetch_row(res);
fprintf(f, " %-16s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %s\n",
row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]);
}
}
free(res);
return 0;
}
@ -334,8 +336,7 @@ editperm(MYSQL *pmysql, const char *db)
strcpy(cmd, editor);
strcat(cmd, " ");
strcat(cmd, fn);
if (system(cmd) == -1)
{
if (system(cmd) == -1) {
dberror(NULL, "Failed to execute '%s'\n", cmd);
perror("system");
return 1;
@ -344,8 +345,7 @@ editperm(MYSQL *pmysql, const char *db)
/* parse */
f = fopen(fn, "r");
lines = 0;
while (fgets(line, sizeof(line), f))
{
while (fgets(line, sizeof(line), f)) {
cp = strchr(line, '\n');
if (cp)
*cp = '\0';
@ -417,10 +417,10 @@ editperm(MYSQL *pmysql, const char *db)
for (i = 0; i < lines; i++)
{
#ifdef DEBUG
#ifdef DEBUG
puts(queries[i]);
putchar('\n');
#endif
#endif
if (mysql_query(pmysql, queries[i]))
dberror(pmysql, "Failed to insert grant line %d.", i + 1);
}
@ -484,16 +484,15 @@ main(int argc, char *argv[])
if (mysql_select_db(&mysql, db_name))
return dberror(&mysql, "Cannot select database '%s'.", db_name);
if ((command == c_show) && (argc == 2))
{
if ((command == c_show) && (argc == 2)) {
dblist = list(&mysql);
p = dblist;
while (*p)
{
while (*p) {
show(&mysql, *p);
free(*p);
p++;
}
free(*p);
free(dblist);
}
else {
@ -502,7 +501,7 @@ main(int argc, char *argv[])
for (i = 2; i < argc; i++) {
// HE HE
strncpy(db, argv[i], 32);
db[33] = '\0';
db[32] = '\0';
if (! (owner(db) || member(db))) {
dberror(NULL, "You are not the owner of '%s'. Skipping.",
@ -533,6 +532,7 @@ main(int argc, char *argv[])
return dberror(NULL, "This point should never be reached!");
}
} // for
free(db);
} // else
mysql_reload(&mysql);