Fossil SCM

Add the obscure() shell function. Corresponding unobscure() is not provided.

drh 2020-06-27 14:48 trunk merge
Commit f7e572b0407fa2b69544def18d632b20e5543512b0857d2dc2543e0b09fa8536
1 file changed +37
+37
--- src/db.c
+++ src/db.c
@@ -1022,10 +1022,45 @@
10221022
return;
10231023
}
10241024
decode16(zIn, zOut, nIn);
10251025
sqlite3_result_blob(context, zOut, nIn/2, sqlite3_free);
10261026
}
1027
+
1028
+/*
1029
+** Return the XOR-obscured version of the input text. Useful for
1030
+** updating authentication strings in Fossil settings. To change
1031
+** the password locally stored for sync, for instance:
1032
+**
1033
+** echo "UPDATE config
1034
+** SET value = obscure('monkey123')
1035
+** WHERE name = 'last-sync-pw'" |
1036
+** fossil sql
1037
+**
1038
+** Note that user.pw uses a different obscuration algorithm, but
1039
+** you don't need to use 'fossil sql' for that anyway. Just call
1040
+**
1041
+** fossil user pass monkey123
1042
+**
1043
+** to change the local user entry's password in the same way.
1044
+*/
1045
+void db_obscure(
1046
+ sqlite3_context *context,
1047
+ int argc,
1048
+ sqlite3_value **argv
1049
+){
1050
+ const unsigned char *zIn = sqlite3_value_text(argv[0]);
1051
+ int nIn = sqlite3_value_bytes(argv[0]);
1052
+ char *zOut, *zTemp;
1053
+ if( 0==zIn ) return;
1054
+ if( 0==(zOut = sqlite3_malloc64( nIn * 2 + 3 )) ){
1055
+ sqlite3_result_error_nomem(context);
1056
+ return;
1057
+ }
1058
+ strcpy(zOut, zTemp = obscure((char*)zIn));
1059
+ fossil_free(zTemp);
1060
+ sqlite3_result_text(context, zOut, strlen(zOut), sqlite3_free);
1061
+}
10271062
10281063
/*
10291064
** Register the SQL functions that are useful both to the internal
10301065
** representation and to the "fossil sql" command.
10311066
*/
@@ -1050,10 +1085,12 @@
10501085
capability_fullcap, 0, 0);
10511086
sqlite3_create_function(db, "find_emailaddr", 1, SQLITE_UTF8, 0,
10521087
alert_find_emailaddr_func, 0, 0);
10531088
sqlite3_create_function(db, "display_name", 1, SQLITE_UTF8, 0,
10541089
alert_display_name_func, 0, 0);
1090
+ sqlite3_create_function(db, "obscure", 1, SQLITE_UTF8, 0,
1091
+ db_obscure, 0, 0);
10551092
}
10561093
10571094
#if USE_SEE
10581095
/*
10591096
** This is a pointer to the saved database encryption key string.
10601097
--- src/db.c
+++ src/db.c
@@ -1022,10 +1022,45 @@
1022 return;
1023 }
1024 decode16(zIn, zOut, nIn);
1025 sqlite3_result_blob(context, zOut, nIn/2, sqlite3_free);
1026 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1027
1028 /*
1029 ** Register the SQL functions that are useful both to the internal
1030 ** representation and to the "fossil sql" command.
1031 */
@@ -1050,10 +1085,12 @@
1050 capability_fullcap, 0, 0);
1051 sqlite3_create_function(db, "find_emailaddr", 1, SQLITE_UTF8, 0,
1052 alert_find_emailaddr_func, 0, 0);
1053 sqlite3_create_function(db, "display_name", 1, SQLITE_UTF8, 0,
1054 alert_display_name_func, 0, 0);
 
 
1055 }
1056
1057 #if USE_SEE
1058 /*
1059 ** This is a pointer to the saved database encryption key string.
1060
--- src/db.c
+++ src/db.c
@@ -1022,10 +1022,45 @@
1022 return;
1023 }
1024 decode16(zIn, zOut, nIn);
1025 sqlite3_result_blob(context, zOut, nIn/2, sqlite3_free);
1026 }
1027
1028 /*
1029 ** Return the XOR-obscured version of the input text. Useful for
1030 ** updating authentication strings in Fossil settings. To change
1031 ** the password locally stored for sync, for instance:
1032 **
1033 ** echo "UPDATE config
1034 ** SET value = obscure('monkey123')
1035 ** WHERE name = 'last-sync-pw'" |
1036 ** fossil sql
1037 **
1038 ** Note that user.pw uses a different obscuration algorithm, but
1039 ** you don't need to use 'fossil sql' for that anyway. Just call
1040 **
1041 ** fossil user pass monkey123
1042 **
1043 ** to change the local user entry's password in the same way.
1044 */
1045 void db_obscure(
1046 sqlite3_context *context,
1047 int argc,
1048 sqlite3_value **argv
1049 ){
1050 const unsigned char *zIn = sqlite3_value_text(argv[0]);
1051 int nIn = sqlite3_value_bytes(argv[0]);
1052 char *zOut, *zTemp;
1053 if( 0==zIn ) return;
1054 if( 0==(zOut = sqlite3_malloc64( nIn * 2 + 3 )) ){
1055 sqlite3_result_error_nomem(context);
1056 return;
1057 }
1058 strcpy(zOut, zTemp = obscure((char*)zIn));
1059 fossil_free(zTemp);
1060 sqlite3_result_text(context, zOut, strlen(zOut), sqlite3_free);
1061 }
1062
1063 /*
1064 ** Register the SQL functions that are useful both to the internal
1065 ** representation and to the "fossil sql" command.
1066 */
@@ -1050,10 +1085,12 @@
1085 capability_fullcap, 0, 0);
1086 sqlite3_create_function(db, "find_emailaddr", 1, SQLITE_UTF8, 0,
1087 alert_find_emailaddr_func, 0, 0);
1088 sqlite3_create_function(db, "display_name", 1, SQLITE_UTF8, 0,
1089 alert_display_name_func, 0, 0);
1090 sqlite3_create_function(db, "obscure", 1, SQLITE_UTF8, 0,
1091 db_obscure, 0, 0);
1092 }
1093
1094 #if USE_SEE
1095 /*
1096 ** This is a pointer to the saved database encryption key string.
1097

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button