Check-in [0c6ea0d93f]
Not logged in
Overview

SHA1 Hash:0c6ea0d93f036473074a5dd93870ad1b51b92cd8
Date: 2008-11-20 01:07:10
User: drh
Comment:When creating a new repository or cloning a repository, print the initial administrator password on standard output. This is intended to help new users figure out how to log in. Ticket ca08d51f19
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/clone.c from [58d2271cc8] to [bf4ca8abfd].

@@ -36,10 +36,11 @@
 **
 ** Make a clone of a repository specified by URL in the local
 ** file named FILENAME.
 */
 void clone_cmd(void){
+  char *zPassword;
   url_proxy_options();
   if( g.argc!=4 ){
     usage("FILE-OR-URL NEW-REPOSITORY");
   }
   db_open_config();
@@ -55,10 +56,14 @@
     db_record_repository_filename(g.argv[3]);
     db_multi_exec(
       "REPLACE INTO config(name,value)"
       " VALUES('server-code', lower(hex(randomblob(20))));"
     );
+    g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
+    if( g.zLogin==0 ){
+      db_create_default_users(1);
+    }
     printf("Repository cloned into %s\n", g.argv[3]);
   }else{
     db_create_repository(g.argv[3]);
     db_open_repository(g.argv[3]);
     db_begin_transaction();
@@ -82,7 +87,11 @@
     db_open_repository(g.argv[3]);
   }
   db_begin_transaction();
   printf("Rebuilding repository meta-data...\n");
   rebuild_db(0, 1);
+  printf("project-id: %s\n", db_get("project-code", 0));
+  printf("server-id:  %s\n", db_get("server-code", 0));
+  zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
+  printf("admin-user: %s (password is \"%s\")\n", g.zLogin, zPassword);
   db_end_transaction(0);
 }

Modified src/configure.c from [2a0972b75d] to [a5fbc772d1].

@@ -479,11 +479,11 @@
       if( (aConfig[i].groupMask & mask)==0 ) continue;
       if( zName[0]!='@' ){
         db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
       }else if( strcmp(zName,"@user")==0 ){
         db_multi_exec("DELETE FROM user");
-        db_create_default_users();
+        db_create_default_users(0);
       }else if( strcmp(zName,"@concealed")==0 ){
         db_multi_exec("DELETE FROM concealed");
       }else if( strcmp(zName,"@shun")==0 ){
         db_multi_exec("DELETE FROM shun");
       }else if( strcmp(zName,"@reportfmt")==0 ){

Modified src/db.c from [cb3d7d6650] to [63d9c57b09].

@@ -851,11 +851,11 @@
 }
 
 /*
 ** Create the default user accounts in the USER table.
 */
-void db_create_default_users(void){
+void db_create_default_users(int setupUserOnly){
   const char *zUser;
   zUser = db_get("default-user", 0);
   if( zUser==0 ){
 #ifdef __MINGW32__
     zUser = getenv("USERNAME");
@@ -866,20 +866,22 @@
   if( zUser==0 ){
     zUser = "root";
   }
   db_multi_exec(
      "INSERT INTO user(login, pw, cap, info)"
-     "VALUES(%Q,'','s','')", zUser
+     "VALUES(%Q,lower(hex(randomblob(3))),'s','')", zUser
   );
-  db_multi_exec(
-     "INSERT INTO user(login,pw,cap,info)"
-     "   VALUES('anonymous','anonymous','ghknw','Anon');"
-     "INSERT INTO user(login,pw,cap,info)"
-     "   VALUES('nobody','','jor','Nobody');"
-     "INSERT INTO user(login,pw,cap,info)"
-     "   VALUES('developer','','deipt','Dev');"
-  );
+  if( !setupUserOnly ){
+    db_multi_exec(
+       "INSERT INTO user(login,pw,cap,info)"
+       "   VALUES('anonymous','anonymous','ghknw','Anon');"
+       "INSERT INTO user(login,pw,cap,info)"
+       "   VALUES('nobody','','jor','Nobody');"
+       "INSERT INTO user(login,pw,cap,info)"
+       "   VALUES('developer','','deipt','Dev');"
+    );
+  }
 }
 
 /*
 ** Fill an empty repository database with the basic information for a
 ** repository. This function is shared between 'create_repository_cmd'
@@ -905,11 +907,11 @@
       " VALUES('project-code', lower(hex(randomblob(20))));"
     );
   }
   if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
   if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
-  db_create_default_users();
+  db_create_default_users(0);
   user_select();
 
   if (makeInitialVersion){
     blob_zero(&manifest);
     blob_appendf(&manifest, "C initial\\sempty\\sbaseline\n");
@@ -935,10 +937,11 @@
 ** Create a repository for a new project in the file named FILENAME.
 ** This command is distinct from "clone".  The "clone" command makes
 ** a copy of an existing project.  This command starts a new project.
 */
 void create_repository_cmd(void){
+  char *zPassword;
   if( g.argc!=3 ){
     usage("REPOSITORY-NAME");
   }
   db_create_repository(g.argv[2]);
   db_open_repository(g.argv[2]);
@@ -946,11 +949,12 @@
   db_begin_transaction();
   db_initial_setup(1, 1);
   db_end_transaction(0);
   printf("project-id: %s\n", db_get("project-code", 0));
   printf("server-id:  %s\n", db_get("server-code", 0));
-  printf("admin-user: %s (no password set yet!)\n", g.zLogin);
+  zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
+  printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
   printf("baseline:   %s\n", db_text(0, "SELECT uuid FROM blob"));
 }
 
 /*
 ** SQL functions for debugging.