Skisse for endring slik at References kan settes.

This commit is contained in:
Aslak Raanes 2018-03-05 15:38:57 +01:00
parent 20ffd6693d
commit 63b59e05df
1 changed files with 23 additions and 17 deletions

View File

@ -98,16 +98,17 @@ usage_editperm()
printf("Lines starting with # are ignored.\n"); printf("Lines starting with # are ignored.\n");
printf("\n"); printf("\n");
printf("The Y/N-values corresponds to the following mysql privileges:\n"); printf("The Y/N-values corresponds to the following mysql privileges:\n");
printf(" Select - Enables use of SELECT\n"); printf(" Select - Enables use of SELECT\n");
printf(" Insert - Enables use of INSERT\n"); printf(" Insert - Enables use of INSERT\n");
printf(" Update - Enables use of UPDATE\n"); printf(" Update - Enables use of UPDATE\n");
printf(" Delete - Enables use of DELETE\n"); printf(" Delete - Enables use of DELETE\n");
printf(" Create - Enables use of CREATE TABLE\n"); printf(" Create - Enables use of CREATE TABLE\n");
printf(" Drop - Enables use of DROP TABLE\n"); printf(" Drop - Enables use of DROP TABLE\n");
printf(" Alter - Enables use of ALTER TABLE\n"); printf(" Alter - Enables use of ALTER TABLE\n");
printf(" Index - Enables use of CREATE INDEX and DROP INDEX\n"); printf(" Index - Enables use of CREATE INDEX and DROP INDEX\n");
printf(" Temp - Enables use of CREATE TEMPORARY TABLE\n"); printf(" Temp - Enables use of CREATE TEMPORARY TABLE\n");
printf(" Lock - Enables use of LOCK TABLE\n"); printf(" Lock - Enables use of LOCK TABLE\n");
printf(" References - Enables use of REFERENCES\n");
printf("\n"); printf("\n");
printf("Report bugs to orakel@ntnu.no\n"); printf("Report bugs to orakel@ntnu.no\n");
return 0; return 0;
@ -309,7 +310,8 @@ writeperm(FILE *f, MYSQL *pmysql, const char *db)
end = strmov(query, "SELECT user,select_priv,insert_priv,update_priv," end = strmov(query, "SELECT user,select_priv,insert_priv,update_priv,"
"delete_priv,create_priv,drop_priv," "delete_priv,create_priv,drop_priv,"
"alter_priv,index_priv," "alter_priv,index_priv,"
"create_tmp_table_priv,lock_tables_priv " "create_tmp_table_priv,lock_tables_priv,"
"References_priv "
"FROM db WHERE db = '"); "FROM db WHERE db = '");
end += mysql_real_escape_string(pmysql, end, db, strlen(db)); end += mysql_real_escape_string(pmysql, end, db, strlen(db));
*end++ = '\''; *end++ = '\'';
@ -324,18 +326,18 @@ writeperm(FILE *f, MYSQL *pmysql, const char *db)
rows = mysql_num_rows(res); rows = mysql_num_rows(res);
fprintf(f, "# User " fprintf(f, "# User "
"Select Insert Update Delete Create Drop Alter Index " "Select Insert Update Delete Create Drop Alter Index "
" Temp Lock\n"); " Temp Lock References\n");
fprintf(f, "# ---------------- " fprintf(f, "# ---------------- "
"------ ------ ------ ------ ------ ---- ----- ----- " "------ ------ ------ ------ ------ ---- ----- ----- "
" ---- ----\n"); " ---- ---- ----------\n");
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 %-7s %-7s %s\n", fprintf(f, " %-16s %-7s %-7s %-7s %-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[9], row[10]); row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11]);
} }
} }
mysql_free_result(res); mysql_free_result(res);
@ -368,7 +370,7 @@ editperm(MYSQL *pmysql, const char *db)
char *cp; /* used to interate through a line */ char *cp; /* used to interate through a line */
char *user, *select_priv, *insert_priv, *update_priv, *delete_priv, char *user, *select_priv, *insert_priv, *update_priv, *delete_priv,
*create_priv, *drop_priv, *alter_priv, *index_priv, *create_tmp_table_priv, *create_priv, *drop_priv, *alter_priv, *index_priv, *create_tmp_table_priv,
*lock_tables_priv; *lock_tables_priv, *References_priv;
char query[4096], *end; /* used to build a query */ char query[4096], *end; /* used to build a query */
char *queries[MAX_GRANTS]; /* insert queries */ char *queries[MAX_GRANTS]; /* insert queries */
int lines; /* number of grant lines processed */ int lines; /* number of grant lines processed */
@ -484,6 +486,8 @@ editperm(MYSQL *pmysql, const char *db)
CHECK_PRIV(create_tmp_table_priv); CHECK_PRIV(create_tmp_table_priv);
STRTOK_WHITESPACE(lock_tables_priv, NULL); STRTOK_WHITESPACE(lock_tables_priv, NULL);
CHECK_PRIV(lock_tables_priv); CHECK_PRIV(lock_tables_priv);
STRTOK_WHITESPACE(References_priv, NULL);
CHECK_PRIV(References_priv);
#undef STRTOK_WHITESPACE #undef STRTOK_WHITESPACE
#undef CHECK_PRIV #undef CHECK_PRIV
@ -492,7 +496,8 @@ editperm(MYSQL *pmysql, const char *db)
"host,db,user,select_priv,insert_priv," "host,db,user,select_priv,insert_priv,"
"update_priv,delete_priv,create_priv," "update_priv,delete_priv,create_priv,"
"drop_priv,alter_priv,index_priv," "drop_priv,alter_priv,index_priv,"
"create_tmp_table_priv,lock_tables_priv" "create_tmp_table_priv,lock_tables_priv,"
"References_priv"
") VALUES ("); ") VALUES (");
end = strmov(end, "'%'"); end = strmov(end, "'%'");
@ -516,6 +521,7 @@ editperm(MYSQL *pmysql, const char *db)
APPEND(index_priv); APPEND(index_priv);
APPEND(create_tmp_table_priv); APPEND(create_tmp_table_priv);
APPEND(lock_tables_priv); APPEND(lock_tables_priv);
APPEND(References_priv);
*end++ = ')'; *end++ = ')';
*end = '\0'; *end = '\0';