aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2014-09-10 19:01:14 +0000
committerdrh <drh@noemail.net>2014-09-10 19:01:14 +0000
commitf442e33e3a794b198071a9c5f76aa33eb74c3327 (patch)
treedac5fa82690fd0d639ad40c31cda70567b6a0aa7 /src
parente933b83f029d0c749346391c86a47217f7e294cb (diff)
downloadsqlite-f442e33e3a794b198071a9c5f76aa33eb74c3327.tar.gz
sqlite-f442e33e3a794b198071a9c5f76aa33eb74c3327.zip
Add the ".user" shell command and implement the sqlite3_user_add()
routine. Incremental check-in. The code compiles but does not work. FossilOrigin-Name: a0455f9deb603bf91684158d911269622720fc1a
Diffstat (limited to 'src')
-rw-r--r--src/func.c3
-rw-r--r--src/prepare.c2
-rw-r--r--src/shell.c64
-rw-r--r--src/sqlite.h.in1
-rw-r--r--src/sqliteInt.h2
5 files changed, 71 insertions, 1 deletions
diff --git a/src/func.c b/src/func.c
index e338ab842..94ad1b62d 100644
--- a/src/func.c
+++ b/src/func.c
@@ -1695,6 +1695,9 @@ void sqlite3RegisterGlobalFunctions(void){
FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
+#if SQLITE_USER_AUTHENTICATION
+ FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
+#endif
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
diff --git a/src/prepare.c b/src/prepare.c
index d3531f114..e1739ba3f 100644
--- a/src/prepare.c
+++ b/src/prepare.c
@@ -722,7 +722,7 @@ static int sqlite3LockAndPrepare(
db->auth.authLevel = authLevel;
}
if( db->auth.authLevel<UAUTH_User ){
- sqlite3ErrorWithMsg(db, SQLITE_ERROR, "user not authenticated");
+ sqlite3ErrorWithMsg(db, SQLITE_AUTH_USER, "user not authenticated");
sqlite3_mutex_leave(db->mutex);
return SQLITE_ERROR;
}
diff --git a/src/shell.c b/src/shell.c
index afe01ef1a..2312a7d32 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -33,6 +33,9 @@
#include <stdio.h>
#include <assert.h>
#include "sqlite3.h"
+#if SQLITE_USER_AUTHENTICATION
+# include "sqlite3userauth.h"
+#endif
#include <ctype.h>
#include <stdarg.h>
@@ -3435,6 +3438,67 @@ static int do_meta_command(char *zLine, ShellState *p){
#endif
}else
+#if SQLITE_USER_AUTHENTICATION
+ if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
+ if( nArg<2 ){
+ fprintf(stderr, "Usage: .user SUBCOMMAND ...\n");
+ rc = 1;
+ goto meta_command_exit;
+ }
+ if( strcmp(azArg[1],"login")==0 ){
+ if( nArg!=4 ){
+ fprintf(stderr, "Usage: .user login USER PASSWORD\n");
+ rc = 1;
+ goto meta_command_exit;
+ }
+ rc = sqlite3_user_authenticate(p->db, azArg[2], (int)strlen(azArg[3]), azArg[3]);
+ if( rc ){
+ fprintf(stderr, "Authentication failed for user %s\n", azArg[2]);
+ rc = 1;
+ }
+ }else if( strcmp(azArg[1],"add")==0 ){
+ if( nArg!=5 ){
+ fprintf(stderr, "Usage: .user add USER ISADMIN PASSWORD\n");
+ rc = 1;
+ goto meta_command_exit;
+ }
+ rc = sqlite3_user_add(p->db, azArg[2], booleanValue(azArg[3]),
+ (int)strlen(azArg[4]), azArg[4]);
+ if( rc ){
+ fprintf(stderr, "User-Add failed: %d\n", rc);
+ rc = 1;
+ }
+ }else if( strcmp(azArg[1],"edit")==0 ){
+ if( nArg!=5 ){
+ fprintf(stderr, "Usage: .user edit USER ISADMIN PASSWORD\n");
+ rc = 1;
+ goto meta_command_exit;
+ }
+ rc = sqlite3_user_change(p->db, azArg[2], booleanValue(azArg[3]),
+ (int)strlen(azArg[4]), azArg[4]);
+ if( rc ){
+ fprintf(stderr, "User-Edit failed: %d\n", rc);
+ rc = 1;
+ }
+ }else if( strcmp(azArg[1],"delete")==0 ){
+ if( nArg!=3 ){
+ fprintf(stderr, "Usage: .user delete USER\n");
+ rc = 1;
+ goto meta_command_exit;
+ }
+ rc = sqlite3_user_delete(p->db, azArg[2]);
+ if( rc ){
+ fprintf(stderr, "User-Delete failed: %d\n", rc);
+ rc = 1;
+ }
+ }else{
+ fprintf(stderr, "Usage: .user login|add|edit|delete ...\n");
+ rc = 1;
+ goto meta_command_exit;
+ }
+ }else
+#endif /* SQLITE_USER_AUTHENTICATION */
+
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
sqlite3_libversion(), sqlite3_sourceid());
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 56dede8ba..e947c3e19 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -492,6 +492,7 @@ int sqlite3_exec(
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
+#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
/*
** CAPI3REF: Flags For File Open Operations
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 0849ee842..9ef4e3620 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -1010,6 +1010,8 @@ struct sqlite3_userauth {
/* Functions used only by user authorization logic */
int sqlite3UserAuthTable(const char*);
int sqlite3UserAuthCheckLogin(sqlite3*,const char*,u8*);
+void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**);
+
#endif /* SQLITE_USER_AUTHENTICATION */