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 * functions used by mysql-dbadm.c and mysql-useradm.c
* *
@ -22,7 +22,7 @@
char *program_name; 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 int
@ -38,8 +38,7 @@ wrong_use(char *format, ...)
{ {
va_list ap; va_list ap;
if (format) if (format) {
{
fprintf(stderr, "%s: ", program_name); fprintf(stderr, "%s: ", program_name);
va_start(ap, format); va_start(ap, format);
vfprintf(stderr, format, ap); vfprintf(stderr, format, ap);
@ -66,8 +65,7 @@ dberror(MYSQL *pmysql, char *format, ...)
va_end(ap); va_end(ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
if (pmysql) if (pmysql) {
{
errmsg = mysql_error(pmysql); errmsg = mysql_error(pmysql);
if ((errmsg) && (strcmp(errmsg, "") != 0)) if ((errmsg) && (strcmp(errmsg, "") != 0))
fprintf(stderr, "mysql: %s\n", errmsg); fprintf(stderr, "mysql: %s\n", errmsg);
@ -102,8 +100,7 @@ owner(char *name)
struct passwd *p; struct passwd *p;
p = getpwuid(getuid()); p = getpwuid(getuid());
if (!p) if (!p) {
{
dberror(NULL, "Failed to look up your UNIX username."); dberror(NULL, "Failed to look up your UNIX username.");
exit(1); exit(1);
} }
@ -182,9 +179,10 @@ member(char *gr) {
printf("You have access to '%s'\n", gr); printf("You have access to '%s'\n", gr);
#endif #endif
return 1; /* OK */ return 1; /* OK */
} else } else {
*g->gr_mem++; *g->gr_mem++;
} }
}
#if DEBUG #if DEBUG
printf("You have no access to '%s'\n", gr); printf("You have no access to '%s'\n", gr);
#endif #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 * mysql-dbadm.c
* *
@ -56,9 +56,7 @@ strtok_whitespace(char *s)
if (cp == NULL) if (cp == NULL)
return r; return r;
while ((*cp == ' ') || (*cp == '\t')) while ((*cp == ' ') || (*cp == '\t'))
{
*cp++ = '\0'; *cp++ = '\0';
}
return r; return r;
} }
@ -159,8 +157,7 @@ list(MYSQL *pmysql)
char *cp_kopi; char *cp_kopi;
p = getpwuid(getuid()); p = getpwuid(getuid());
if (!p) if (!p) {
{
dberror(NULL, "Failed to lookup your UNIX username."); dberror(NULL, "Failed to lookup your UNIX username.");
exit(1); exit(1);
} }
@ -209,14 +206,17 @@ list(MYSQL *pmysql)
dblist = realloc(dblist, (numgroupdbs+2) * sizeof(char *)); 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))) { if ((row = mysql_fetch_row(res))) {
dblist[counter++] = strdup(row[0]); dblist[counter++] = strdup(row[0]);
} }
} }
}
free(wild); free(wild);
free(res);
free(cp_kopi);
cp++; cp++;
} }
@ -230,18 +230,17 @@ list(MYSQL *pmysql)
rows = mysql_num_rows(res); rows = mysql_num_rows(res);
dblist = realloc(dblist, (numgroupdbs+rows+2) * sizeof(char *)); dblist = realloc(dblist, (numgroupdbs+rows+2) * sizeof(char *));
if (!dblist) if (!dblist) {
{
dberror(NULL, "Out of memory.\n"); dberror(NULL, "Out of memory.\n");
free(wild); free(wild);
return NULL; return NULL;
} }
for (i = 0; i < rows; i++) for (i = 0; i < rows; i++) {
if ((row = mysql_fetch_row(res))) if ((row = mysql_fetch_row(res))) {
{
dblist[counter++] = strdup(row[0]); dblist[counter++] = strdup(row[0]);
} }
}
res = mysql_list_dbs(pmysql, p->pw_name); res = mysql_list_dbs(pmysql, p->pw_name);
rows = mysql_num_rows(res); rows = mysql_num_rows(res);
@ -250,6 +249,8 @@ list(MYSQL *pmysql)
dblist[counter] = NULL; dblist[counter] = NULL;
free(wild);
free(usr_groups);
return dblist; return dblist;
} }
@ -276,13 +277,14 @@ writeperm(FILE *f, MYSQL *pmysql, const char *db)
if (rows == 0) if (rows == 0)
fprintf(f, "# (no permissions currently granted to any users)\n"); fprintf(f, "# (no permissions currently granted to any users)\n");
else else {
for (i = 0; i < rows; i++) for (i = 0; i < rows; i++) {
{
row = mysql_fetch_row(res); row = mysql_fetch_row(res);
fprintf(f, " %-16s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %s\n", 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]); row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]);
} }
}
free(res);
return 0; return 0;
} }
@ -334,8 +336,7 @@ editperm(MYSQL *pmysql, const char *db)
strcpy(cmd, editor); strcpy(cmd, editor);
strcat(cmd, " "); strcat(cmd, " ");
strcat(cmd, fn); strcat(cmd, fn);
if (system(cmd) == -1) if (system(cmd) == -1) {
{
dberror(NULL, "Failed to execute '%s'\n", cmd); dberror(NULL, "Failed to execute '%s'\n", cmd);
perror("system"); perror("system");
return 1; return 1;
@ -344,8 +345,7 @@ editperm(MYSQL *pmysql, const char *db)
/* parse */ /* parse */
f = fopen(fn, "r"); f = fopen(fn, "r");
lines = 0; lines = 0;
while (fgets(line, sizeof(line), f)) while (fgets(line, sizeof(line), f)) {
{
cp = strchr(line, '\n'); cp = strchr(line, '\n');
if (cp) if (cp)
*cp = '\0'; *cp = '\0';
@ -484,16 +484,15 @@ main(int argc, char *argv[])
if (mysql_select_db(&mysql, db_name)) if (mysql_select_db(&mysql, db_name))
return dberror(&mysql, "Cannot select database '%s'.", 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); dblist = list(&mysql);
p = dblist; p = dblist;
while (*p) while (*p) {
{
show(&mysql, *p); show(&mysql, *p);
free(*p); free(*p);
p++; p++;
} }
free(*p);
free(dblist); free(dblist);
} }
else { else {
@ -502,7 +501,7 @@ main(int argc, char *argv[])
for (i = 2; i < argc; i++) { for (i = 2; i < argc; i++) {
// HE HE // HE HE
strncpy(db, argv[i], 32); strncpy(db, argv[i], 32);
db[33] = '\0'; db[32] = '\0';
if (! (owner(db) || member(db))) { if (! (owner(db) || member(db))) {
dberror(NULL, "You are not the owner of '%s'. Skipping.", 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!"); return dberror(NULL, "This point should never be reached!");
} }
} // for } // for
free(db);
} // else } // else
mysql_reload(&mysql); mysql_reload(&mysql);