Add local changes from the past 7 years

This commit is contained in:
2016-08-02 06:10:45 +00:00
parent 1d81d8820f
commit c2aa958bb3
11 changed files with 3999 additions and 5912 deletions

View File

@@ -77,6 +77,8 @@ usage()
printf(" favorite editor will be started, allowing you\n");
printf(" to make changes to the permission table.\n");
printf("\n");
printf("This program now has super-cow powers.");
printf("\n");
printf("Report bugs to ljosa@initio.no\n");
return 0;
}
@@ -170,24 +172,24 @@ writeperm(FILE *f, MYSQL *pmysql, const char *db)
MYSQL_ROW row;
sprintf(query, "select user,select_priv,insert_priv,update_priv,"
"delete_priv,create_priv,alter_priv,drop_priv from db where db='%s'", db);
"delete_priv,create_priv,alter_priv,drop_priv, index_priv from db where db='%s'", db);
if (mysql_query(pmysql, query))
return dberror(pmysql, "Query for permissions failed.");
res = mysql_store_result(pmysql);
rows = mysql_num_rows(res);
fprintf(f, "# User "
"Select Insert Update Delete Create Alter Drop\n");
"Select Insert Update Delete Create Alter Drop Index\n");
fprintf(f, "# ---------------- "
"------ ------ ------ ------ ------ ------ ------\n");
"------ ------ ------ ------ ------ ------ ------ ------\n");
if (rows == 0)
fprintf(f, "# (no permissions currently granted to any users)\n");
else
for (i = 0; i < rows; i++)
{
row = mysql_fetch_row(res);
fprintf(f, " %-16s %-7s %-7s %-7s %-7s %-7s %-7s %s\n",
row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]);
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]);
}
}
@@ -216,13 +218,13 @@ editperm(MYSQL *pmysql, const char *db)
char line[1024]; /* buffer to hold one line */
char *cp; /* used to interate through a line */
char *user, *select_priv, *insert_priv, *update_priv, *delete_priv,
*create_priv, *alter_priv, *drop_priv;
*create_priv, *alter_priv, *drop_priv, *index_priv;
char query[1024]; /* used to build a query */
char *queries[MAX_GRANTS]; /* insert queries */
int lines; /* number of grant lines processed */
int i; /* iterate through lines[] */
mktemp(fn);
mkstemp(fn);
if (strcmp(fn, "") == 0)
return dberror(NULL, "Cannot create a unique temporary file name.");
@@ -288,15 +290,18 @@ editperm(MYSQL *pmysql, const char *db)
CHECK_PRIV(alter_priv);
STRTOK_WHITESPACE(drop_priv, NULL);
CHECK_PRIV(drop_priv);
STRTOK_WHITESPACE(index_priv, NULL);
CHECK_PRIV(index_priv);
#undef STRTOK_WHITESPACE
#undef CHECK_PRIV
sprintf(query, "insert into db(Host, Db, User, Select_priv, Insert_priv, "
"Update_priv, Delete_priv, Create_priv, Alter_priv, Drop_priv) "
"values ('%%', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
"Update_priv, Delete_priv, Create_priv, Alter_priv, Drop_priv, Index_priv) "
"values ('%%', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
db, user, select_priv, insert_priv, update_priv, delete_priv,
create_priv, alter_priv, drop_priv);
create_priv, alter_priv, drop_priv, index_priv);
queries[lines] = strdup(query);
lines++;
if (lines >= MAX_GRANTS)
@@ -322,7 +327,7 @@ editperm(MYSQL *pmysql, const char *db)
#ifdef DEBUG
puts(queries[i]);
putchar('\n');
#endif DEBUG
#endif //DEBUG
if (mysql_query(pmysql, queries[i]))
dberror(pmysql, "Failed to insert grant line %d.", i + 1);
}
@@ -335,7 +340,7 @@ int
main(int argc, char *argv[])
{
int i;
enum { c_create, c_drop, c_editperm, c_show } command;
enum { c_create, c_drop, c_editperm, c_show, c_moo } command;
MYSQL mysql;
mysql_init(&mysql);
char **dblist, **p;
@@ -362,11 +367,14 @@ main(int argc, char *argv[])
command = c_editperm;
else if (strcmp(argv[1], "show") == 0)
command = c_show;
else if (strcmp(argv[1], "moo") == 0){
printf("mooo!\n");
}
else
return wrong_use("unrecognized command"); /* XXX */
/* all other than show requires at lease one DATABASE argument. */
if ((command != c_show) && (argc < 3))
if ((command != c_show) && (argc < 3))
return wrong_use(NULL);
/* connect to the database server and select the mysql database */
@@ -388,7 +396,7 @@ main(int argc, char *argv[])
}
free(dblist);
}
else
else
{
/* for each supplied database name, perform the requested action */
for (i = 2; i < argc; i++)