]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the ".auth ON|OFF" command to the command-line shell.
authordrh <drh@noemail.net>
Mon, 4 Apr 2016 17:23:10 +0000 (17:23 +0000)
committerdrh <drh@noemail.net>
Mon, 4 Apr 2016 17:23:10 +0000 (17:23 +0000)
FossilOrigin-Name: 65c7bcc42786a254966c531ba9062abb8fc8c5bf

manifest
manifest.uuid
src/shell.c

index 9c351dc120c8b324696fb3fa2c2cc8e161bf9f84..f50d302e4fca11f9489992bfabf8c943e9c5dccb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Test\sthat\sthe\sview\sname\sis\spassed\sto\sthe\sauthorization\scallback\swhen\sa\sSELECT\sstatement\sis\srun\son\sa\sview.
-D 2016-04-04T16:40:44.335
+C Add\sthe\s".auth\sON|OFF"\scommand\sto\sthe\scommand-line\sshell.
+D 2016-04-04T17:23:10.395
 F Makefile.in e812bb732d7af01baa09f1278bd4f4a2e3a09449
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc fe57d7e3e74fa383fd01ced796c0ffd966fc094a
@@ -376,7 +376,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
 F src/resolve.c b8f7174e5f8c33c44ded3a25a973d0bb89228c20
 F src/rowset.c 9fe4b3ad7cc00944386bb600233d8f523de07a6e
 F src/select.c 7849cee0a01952a9c93cd28989daedfa57731143
-F src/shell.c faa783401b0c25e52e4054a7292a78ab2f76d210
+F src/shell.c e0996a0be612c8d2630fdf8bcedf4c4260a29734
 F src/sqlite.h.in c46a7b85d3f37371cacea8f98ec825f5e52c420c
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 98f72cbfe00169c39089115427d06ea05fe4b4a2
@@ -1482,7 +1482,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 42a219668413e18dae917b03b04a21d108cc44be
-R 27f4603d27093d983cb0f53232a8c10f
-U dan
-Z 39b2019f8e2190d9694d9394017c15aa
+P 8627a4cd6d64bd076b56c1e8ccc3b1dfc1b4c07d
+R 327fee759e5533f8bd09762659f3f70b
+U drh
+Z ff39f0b57606b297cab9fa07bc83cd18
index 3507c72f05f234c5f6f18463f301f9cb91ce0845..8a44ee2cd4dcf8b6c2fad7f9ecaf0c04fdd093ad 100644 (file)
@@ -1 +1 @@
-8627a4cd6d64bd076b56c1e8ccc3b1dfc1b4c07d
\ No newline at end of file
+65c7bcc42786a254966c531ba9062abb8fc8c5bf
\ No newline at end of file
index 58a0d7aa516b958ca8315797fe347d75485b45df..809d9d04591310df1e281d5418edfc5e207eeb2e 100644 (file)
@@ -887,6 +887,52 @@ static void interrupt_handler(int NotUsed){
 }
 #endif
 
+/*
+** When the ".auth ON" is set, the following authorizer callback is
+** invoked.  It always returns SQLITE_OK.
+*/
+static int shellAuth(
+  void *pClientData,
+  int op,
+  const char *zA1,
+  const char *zA2,
+  const char *zA3,
+  const char *zA4
+){
+  ShellState *p = (ShellState*)pClientData;
+  static const char *azAction[] = { 0,
+     "CREATE_INDEX",         "CREATE_TABLE",         "CREATE_TEMP_INDEX",
+     "CREATE_TEMP_TABLE",    "CREATE_TEMP_TRIGGER",  "CREATE_TEMP_VIEW",
+     "CREATE_TRIGGER",       "CREATE_VIEW",          "DELETE",
+     "DROP_INDEX",           "DROP_TABLE",           "DROP_TEMP_INDEX",
+     "DROP_TEMP_TABLE",      "DROP_TEMP_TRIGGER",    "DROP_TEMP_VIEW",
+     "DROP_TRIGGER",         "DROP_VIEW",            "INSERT",
+     "PRAGMA",               "READ",                 "SELECT",
+     "TRANSACTION",          "UPDATE",               "ATTACH",
+     "DETACH",               "ALTER_TABLE",          "REINDEX",
+     "ANALYZE",              "CREATE_VTABLE",        "DROP_VTABLE",
+     "FUNCTION",             "SAVEPOINT",            "RECURSIVE"
+  };
+  int i;
+  const char *az[4];
+  az[0] = zA1;
+  az[1] = zA2;
+  az[2] = zA3;
+  az[3] = zA4;
+  raw_printf(p->out, "authorizer: %s", azAction[op]);
+  for(i=0; i<4; i++){
+    raw_printf(p->out, " ");
+    if( az[i] ){
+      output_c_string(p->out, az[i]);
+    }else{
+      raw_printf(p->out, "NULL");
+    }
+  }
+  raw_printf(p->out, "\n");
+  return SQLITE_OK;
+}
+  
+
 /*
 ** This is the callback routine that the shell
 ** invokes for each row of a query result.
@@ -1958,6 +2004,7 @@ static int run_schema_dump_query(
 ** Text of a help message
 */
 static char zHelp[] =
+  ".auth ON|OFF           Show authorizer callbacks\n"
   ".backup ?DB? FILE      Backup DB (default \"main\") to FILE\n"
   ".bail on|off           Stop after hitting an error.  Default OFF\n"
   ".binary on|off         Turn binary output on or off.  Default OFF\n"
@@ -2923,6 +2970,21 @@ static int do_meta_command(char *zLine, ShellState *p){
   if( nArg==0 ) return 0; /* no tokens, no error */
   n = strlen30(azArg[0]);
   c = azArg[0][0];
+
+  if( c=='a' && strncmp(azArg[0], "auth", n)==0 ){
+    if( nArg!=2 ){
+      raw_printf(stderr, "Usage: .auth ON|OFF\n");
+      rc = 1;
+      goto meta_command_exit;
+    }
+    open_db(p, 0);
+    if( booleanValue(azArg[1]) ){
+      sqlite3_set_authorizer(p->db, shellAuth, p);
+    }else{
+      sqlite3_set_authorizer(p->db, 0, 0);
+    }
+  }else
+
   if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
    || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
   ){