Diff
Not logged in

Differences From:

File src/user.c part of check-in [6607844a01] - Added options to the "timeline" CLI command. Additional help comments. by drh on 2007-08-18 11:42:24. [view]

To:

File src/user.c part of check-in [783df88ba8] - Prevent duplicate logins on the "user add" command. Also, allow the login to be specified on the command line. by drh on 2007-10-26 18:18:59. Also file src/user.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46. [view]

@@ -46,8 +46,48 @@
   }
   blob_append(pBlob, z, -1);
 }
 
+#ifdef __MINGW32__
+/*
+** getpass for Windows
+*/
+static char *getpass(const char *prompt){
+  static char pwd[64];
+  size_t i;
+
+  fputs(prompt,stderr);
+  fflush(stderr);
+  for(i=0; i<sizeof(pwd)-1; ++i){
+    pwd[i] = _getch();
+    if(pwd[i]=='\r' || pwd[i]=='\n'){
+      break;
+    }
+    /* BS or DEL */
+    else if(i>0 && (pwd[i]==8 || pwd[i]==127)){
+      i -= 2;
+      continue;
+    }
+    /* CTRL-C */
+    else if(pwd[i]==3) {
+      i=0;
+      break;
+    }
+    /* ESC */
+    else if(pwd[i]==27){
+      i=0;
+      break;
+    }
+    else{
+      fputc('*',stderr);
+    }
+  }
+  pwd[i]='\0';
+  fputs("\n", stderr);
+  return pwd;
+}
+#endif
+
 /*
 ** Do a single prompt for a passphrase.  Store the results in the blob.
 */
 static void prompt_for_passphrase(const char *zPrompt, Blob *pPassphrase){
@@ -126,9 +166,9 @@
 **    %fossil user list
 **
 **        List all users known to the repository
 **
-**    %fossil user new
+**    %fossil user new ?USERNAME?
 **
 **        Create a new user in the repository.  Users can never be
 **        deleted.  They can be denied all access but they must continue
 **        to exist in the database.
@@ -146,9 +186,17 @@
   n = strlen(g.argv[2]);
   if( n>=2 && strncmp(g.argv[2],"new",n)==0 ){
     Blob passwd, login, contact;
 
-    prompt_user("login: ", &login);
+    if( g.argc>=4 ){
+      blob_zero(&login);
+      blob_append(&login, g.argv[3], -1);
+    }else{
+      prompt_user("login: ", &login);
+    }
+    if( db_exists("SELECT 1 FROM user WHERE login=%B", &login) ){
+      fossil_fatal("user %b already exists", &login);
+    }
     prompt_user("contact-info: ", &contact);
     prompt_for_password("password: ", &passwd, 1);
     db_multi_exec(
       "INSERT INTO user(login,pw,cap,info)"
@@ -161,9 +209,9 @@
       printf("%s\n", g.zLogin);
     }else if( g.localOpen ){
       db_lset("default-user", g.zLogin);
     }else{
-      db_set("default-user", g.zLogin);
+      db_set("default-user", g.zLogin, 0);
     }
   }else if( n>=2 && strncmp(g.argv[2],"list",n)==0 ){
     Stmt q;
     db_prepare(&q, "SELECT login, info FROM user ORDER BY login");
@@ -174,9 +222,9 @@
   }else if( n>=2 && strncmp(g.argv[2],"password",2)==0 ){
     char *zPrompt;
     int uid;
     Blob pw;
-    if( g.argc!=4 ) usage("user password USERNAME");
+    if( g.argc!=4 ) usage("password USERNAME");
     uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.argv[3]);
     if( uid==0 ){
       fossil_fatal("no such user: %s", g.argv[3]);
     }
@@ -253,9 +301,10 @@
   if( attempt_user(db_get("default-user", 0)) ) return;
 
   if( attempt_user(getenv("USER")) ) return;
 
-  db_prepare(&s, "SELECT uid, login FROM user WHERE login<>'anonymous'");
+  db_prepare(&s, "SELECT uid, login FROM user"
+                 " WHERE login NOT IN ('anonymous','nobody')");
   if( db_step(&s)==SQLITE_ROW ){
     g.userUid = db_column_int(&s, 0);
     g.zLogin = mprintf("%s", db_column_text(&s, 1));
   }
@@ -272,10 +321,10 @@
 
   if( g.userUid==0 ){
     db_multi_exec(
       "INSERT INTO user(login, pw, cap, info)"
-      "VALUES('anonymous', '', '', '')"
+      "VALUES('anonymous', '', 'cfghjkmnoqw', '')"
     );
     g.userUid = db_last_insert_rowid();
     g.zLogin = "anonymous";
   }
 }