Hex Artifact Content
Not logged in

Artifact 9649e144263c124d53603b4844dea91f9cd1b9a9:

File src/user.c part of check-in [f3807dbd88] - Removed unnecessary items from WWW Configuration, also made RSS Title and Description into generic Project Name and Project Description settings, which will be used elsewhere in the web site. by jnc on 2007-10-10 02:49:29.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 36 20 44 2e 20 52 69 63 68  (c) 2006 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c 64  **.** You should
01f0: 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 61   have received a
0200: 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e 55   copy of the GNU
0210: 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 0a   General Public.
0220: 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e 67  ** License along
0230: 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72 61   with this libra
0240: 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69 74  ry; if not, writ
0250: 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65 65  e to the.** Free
0260: 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 61   Software Founda
0270: 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 54  tion, Inc., 59 T
0280: 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53 75  emple Place - Su
0290: 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73 74  ite 330,.** Bost
02a0: 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31 33  on, MA  02111-13
02b0: 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20 41  07, USA..**.** A
02c0: 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 6e  uthor contact in
02d0: 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 20  formation:.**   
02e0: 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a 2a  drh@hwaci.com.**
02f0: 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 77     http://www.hw
0300: 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a 0a  aci.com/drh/.**.
0310: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a  ***************.
0360: 2a 2a 0a 2a 2a 20 43 6f 6d 6d 61 6e 64 73 20 61  **.** Commands a
0370: 6e 64 20 70 72 6f 63 65 64 75 72 65 73 20 75 73  nd procedures us
0380: 65 64 20 66 6f 72 20 63 72 65 61 74 69 6e 67 2c  ed for creating,
0390: 20 70 72 6f 63 65 73 73 69 6e 67 2c 20 65 64 69   processing, edi
03a0: 74 69 6e 67 2c 20 61 6e 64 0a 2a 2a 20 71 75 65  ting, and.** que
03b0: 72 79 69 6e 67 20 69 6e 66 6f 72 6d 61 74 69 6f  rying informatio
03c0: 6e 20 61 62 6f 75 74 20 75 73 65 72 73 2e 0a 2a  n about users..*
03d0: 2f 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e 66  /.#include "conf
03e0: 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22  ig.h".#include "
03f0: 75 73 65 72 2e 68 22 0a 0a 0a 2f 2a 0a 2a 2a 20  user.h".../*.** 
0400: 53 74 72 69 70 20 6c 65 61 64 69 6e 67 20 61 6e  Strip leading an
0410: 64 20 74 72 61 69 6c 69 6e 67 20 73 70 61 63 65  d trailing space
0420: 20 66 72 6f 6d 20 61 20 73 74 72 69 6e 67 20 61   from a string a
0430: 6e 64 20 61 64 64 20 74 68 65 20 73 74 72 69 6e  nd add the strin
0440: 67 0a 2a 2a 20 6f 6e 74 6f 20 74 68 65 20 65 6e  g.** onto the en
0450: 64 20 6f 66 20 61 20 62 6c 6f 62 2e 0a 2a 2f 0a  d of a blob..*/.
0460: 73 74 61 74 69 63 20 76 6f 69 64 20 73 74 72 69  static void stri
0470: 70 5f 73 74 72 69 6e 67 28 42 6c 6f 62 20 2a 70  p_string(Blob *p
0480: 42 6c 6f 62 2c 20 63 68 61 72 20 2a 7a 29 7b 0a  Blob, char *z){.
0490: 20 20 69 6e 74 20 69 3b 0a 20 20 62 6c 6f 62 5f    int i;.  blob_
04a0: 72 65 73 65 74 28 70 42 6c 6f 62 29 3b 0a 20 20  reset(pBlob);.  
04b0: 77 68 69 6c 65 28 20 69 73 73 70 61 63 65 28 2a  while( isspace(*
04c0: 7a 29 20 29 7b 20 7a 2b 2b 3b 20 7d 0a 20 20 66  z) ){ z++; }.  f
04d0: 6f 72 28 69 3d 30 3b 20 7a 5b 69 5d 3b 20 69 2b  or(i=0; z[i]; i+
04e0: 2b 29 7b 0a 20 20 20 20 69 66 28 20 7a 5b 69 5d  +){.    if( z[i]
04f0: 3d 3d 27 5c 72 27 20 7c 7c 20 7a 5b 69 5d 3d 3d  =='\r' || z[i]==
0500: 27 5c 6e 27 20 29 7b 0a 20 20 20 20 20 20 20 77  '\n' ){.       w
0510: 68 69 6c 65 28 20 69 3e 30 20 26 26 20 69 73 73  hile( i>0 && iss
0520: 70 61 63 65 28 7a 5b 69 2d 31 5d 29 20 29 7b 20  pace(z[i-1]) ){ 
0530: 69 2d 2d 3b 20 7d 0a 20 20 20 20 20 20 20 7a 5b  i--; }.       z[
0540: 69 5d 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 62  i] = 0;.       b
0550: 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20  reak;.    }.    
0560: 69 66 28 20 7a 5b 69 5d 3c 27 20 27 20 29 20 7a  if( z[i]<' ' ) z
0570: 5b 69 5d 20 3d 20 27 20 27 3b 0a 20 20 7d 0a 20  [i] = ' ';.  }. 
0580: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 42 6c   blob_append(pBl
0590: 6f 62 2c 20 7a 2c 20 2d 31 29 3b 0a 7d 0a 0a 23  ob, z, -1);.}..#
05a0: 69 66 64 65 66 20 5f 5f 4d 49 4e 47 57 33 32 5f  ifdef __MINGW32_
05b0: 5f 0a 2f 2a 0a 2a 2a 20 67 65 74 70 61 73 73 20  _./*.** getpass 
05c0: 66 6f 72 20 57 69 6e 64 6f 77 73 0a 2a 2f 0a 73  for Windows.*/.s
05d0: 74 61 74 69 63 20 63 68 61 72 20 2a 67 65 74 70  tatic char *getp
05e0: 61 73 73 28 63 6f 6e 73 74 20 63 68 61 72 20 2a  ass(const char *
05f0: 70 72 6f 6d 70 74 29 7b 0a 20 20 73 74 61 74 69  prompt){.  stati
0600: 63 20 63 68 61 72 20 70 77 64 5b 36 34 5d 3b 0a  c char pwd[64];.
0610: 20 20 73 69 7a 65 5f 74 20 69 3b 0a 0a 20 20 66    size_t i;..  f
0620: 70 75 74 73 28 70 72 6f 6d 70 74 2c 73 74 64 65  puts(prompt,stde
0630: 72 72 29 3b 0a 20 20 66 66 6c 75 73 68 28 73 74  rr);.  fflush(st
0640: 64 65 72 72 29 3b 0a 20 20 66 6f 72 28 69 3d 30  derr);.  for(i=0
0650: 3b 20 69 3c 73 69 7a 65 6f 66 28 70 77 64 29 2d  ; i<sizeof(pwd)-
0660: 31 3b 20 2b 2b 69 29 7b 0a 20 20 20 20 70 77 64  1; ++i){.    pwd
0670: 5b 69 5d 20 3d 20 5f 67 65 74 63 68 28 29 3b 0a  [i] = _getch();.
0680: 20 20 20 20 69 66 28 70 77 64 5b 69 5d 3d 3d 27      if(pwd[i]=='
0690: 5c 72 27 20 7c 7c 20 70 77 64 5b 69 5d 3d 3d 27  \r' || pwd[i]=='
06a0: 5c 6e 27 29 7b 0a 20 20 20 20 20 20 62 72 65 61  \n'){.      brea
06b0: 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 2f 2a 20  k;.    }.    /* 
06c0: 42 53 20 6f 72 20 44 45 4c 20 2a 2f 0a 20 20 20  BS or DEL */.   
06d0: 20 65 6c 73 65 20 69 66 28 69 3e 30 20 26 26 20   else if(i>0 && 
06e0: 28 70 77 64 5b 69 5d 3d 3d 38 20 7c 7c 20 70 77  (pwd[i]==8 || pw
06f0: 64 5b 69 5d 3d 3d 31 32 37 29 29 7b 0a 20 20 20  d[i]==127)){.   
0700: 20 20 20 69 20 2d 3d 20 32 3b 0a 20 20 20 20 20     i -= 2;.     
0710: 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d   continue;.    }
0720: 0a 20 20 20 20 2f 2a 20 43 54 52 4c 2d 43 20 2a  .    /* CTRL-C *
0730: 2f 0a 20 20 20 20 65 6c 73 65 20 69 66 28 70 77  /.    else if(pw
0740: 64 5b 69 5d 3d 3d 33 29 20 7b 0a 20 20 20 20 20  d[i]==3) {.     
0750: 20 69 3d 30 3b 0a 20 20 20 20 20 20 62 72 65 61   i=0;.      brea
0760: 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 2f 2a 20  k;.    }.    /* 
0770: 45 53 43 20 2a 2f 0a 20 20 20 20 65 6c 73 65 20  ESC */.    else 
0780: 69 66 28 70 77 64 5b 69 5d 3d 3d 32 37 29 7b 0a  if(pwd[i]==27){.
0790: 20 20 20 20 20 20 69 3d 30 3b 0a 20 20 20 20 20        i=0;.     
07a0: 20 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20   break;.    }.  
07b0: 20 20 65 6c 73 65 7b 0a 20 20 20 20 20 20 66 70    else{.      fp
07c0: 75 74 63 28 27 2a 27 2c 73 74 64 65 72 72 29 3b  utc('*',stderr);
07d0: 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 70 77 64  .    }.  }.  pwd
07e0: 5b 69 5d 3d 27 5c 30 27 3b 0a 20 20 66 70 75 74  [i]='\0';.  fput
07f0: 73 28 22 5c 6e 22 2c 20 73 74 64 65 72 72 29 3b  s("\n", stderr);
0800: 0a 20 20 72 65 74 75 72 6e 20 70 77 64 3b 0a 7d  .  return pwd;.}
0810: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44  .#endif../*.** D
0820: 6f 20 61 20 73 69 6e 67 6c 65 20 70 72 6f 6d 70  o a single promp
0830: 74 20 66 6f 72 20 61 20 70 61 73 73 70 68 72 61  t for a passphra
0840: 73 65 2e 20 20 53 74 6f 72 65 20 74 68 65 20 72  se.  Store the r
0850: 65 73 75 6c 74 73 20 69 6e 20 74 68 65 20 62 6c  esults in the bl
0860: 6f 62 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f  ob..*/.static vo
0870: 69 64 20 70 72 6f 6d 70 74 5f 66 6f 72 5f 70 61  id prompt_for_pa
0880: 73 73 70 68 72 61 73 65 28 63 6f 6e 73 74 20 63  ssphrase(const c
0890: 68 61 72 20 2a 7a 50 72 6f 6d 70 74 2c 20 42 6c  har *zPrompt, Bl
08a0: 6f 62 20 2a 70 50 61 73 73 70 68 72 61 73 65 29  ob *pPassphrase)
08b0: 7b 0a 20 20 63 68 61 72 20 2a 7a 20 3d 20 67 65  {.  char *z = ge
08c0: 74 70 61 73 73 28 7a 50 72 6f 6d 70 74 29 3b 0a  tpass(zPrompt);.
08d0: 20 20 73 74 72 69 70 5f 73 74 72 69 6e 67 28 70    strip_string(p
08e0: 50 61 73 73 70 68 72 61 73 65 2c 20 7a 29 3b 0a  Passphrase, z);.
08f0: 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72 6f 6d 70 74 20  }../*.** Prompt 
0900: 74 68 65 20 75 73 65 72 20 66 6f 72 20 61 20 70  the user for a p
0910: 61 73 73 77 6f 72 64 2e 20 20 53 74 6f 72 65 20  assword.  Store 
0920: 74 68 65 20 72 65 73 75 6c 74 20 69 6e 20 74 68  the result in th
0930: 65 20 70 50 61 73 73 70 68 72 61 73 65 0a 2a 2a  e pPassphrase.**
0940: 20 62 6c 6f 62 2e 0a 2a 2a 0a 2a 2a 20 42 65 68   blob..**.** Beh
0950: 61 76 69 6f 72 20 69 73 20 63 6f 6e 74 72 6f 6c  avior is control
0960: 6c 65 64 20 62 79 20 74 68 65 20 76 65 72 69 66  led by the verif
0970: 79 20 70 61 72 61 6d 65 74 65 72 3a 0a 2a 2a 0a  y parameter:.**.
0980: 2a 2a 20 20 20 20 20 30 20 20 20 20 20 4a 75 73  **     0     Jus
0990: 74 20 61 73 6b 20 6f 6e 63 65 2e 0a 2a 2a 0a 2a  t ask once..**.*
09a0: 2a 20 20 20 20 20 31 20 20 20 20 20 49 66 20 74  *     1     If t
09b0: 68 65 20 66 69 72 73 74 20 61 6e 73 77 65 72 20  he first answer 
09c0: 69 73 20 61 20 6e 6f 6e 2d 65 6d 70 74 79 20 73  is a non-empty s
09d0: 74 72 69 6e 67 2c 20 61 73 6b 20 66 6f 72 0a 2a  tring, ask for.*
09e0: 2a 20 20 20 20 20 20 20 20 20 20 20 76 65 72 69  *           veri
09f0: 66 69 63 61 74 69 6f 6e 2e 20 20 52 65 70 65 61  fication.  Repea
0a00: 74 20 69 66 20 74 68 65 20 74 77 6f 20 73 74 72  t if the two str
0a10: 69 6e 67 73 20 64 6f 20 6e 6f 74 20 6d 61 74 63  ings do not matc
0a20: 68 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 32 20 20  h..**.**     2  
0a30: 20 20 20 41 73 6b 20 74 77 69 63 65 2c 20 72 65     Ask twice, re
0a40: 70 65 61 74 20 69 66 20 74 68 65 20 73 74 72 69  peat if the stri
0a50: 6e 67 73 20 64 6f 20 6e 6f 74 20 6d 61 74 63 68  ngs do not match
0a60: 2e 0a 2a 2f 0a 76 6f 69 64 20 70 72 6f 6d 70 74  ..*/.void prompt
0a70: 5f 66 6f 72 5f 70 61 73 73 77 6f 72 64 28 0a 20  _for_password(. 
0a80: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 72   const char *zPr
0a90: 6f 6d 70 74 2c 0a 20 20 42 6c 6f 62 20 2a 70 50  ompt,.  Blob *pP
0aa0: 61 73 73 70 68 72 61 73 65 2c 0a 20 20 69 6e 74  assphrase,.  int
0ab0: 20 76 65 72 69 66 79 0a 29 7b 0a 20 20 42 6c 6f   verify.){.  Blo
0ac0: 62 20 73 65 63 6f 6e 64 54 72 79 3b 0a 20 20 62  b secondTry;.  b
0ad0: 6c 6f 62 5f 7a 65 72 6f 28 70 50 61 73 73 70 68  lob_zero(pPassph
0ae0: 72 61 73 65 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65  rase);.  blob_ze
0af0: 72 6f 28 26 73 65 63 6f 6e 64 54 72 79 29 3b 0a  ro(&secondTry);.
0b00: 20 20 77 68 69 6c 65 28 31 29 7b 0a 20 20 20 20    while(1){.    
0b10: 70 72 6f 6d 70 74 5f 66 6f 72 5f 70 61 73 73 70  prompt_for_passp
0b20: 68 72 61 73 65 28 7a 50 72 6f 6d 70 74 2c 20 70  hrase(zPrompt, p
0b30: 50 61 73 73 70 68 72 61 73 65 29 3b 0a 20 20 20  Passphrase);.   
0b40: 20 69 66 28 20 76 65 72 69 66 79 3d 3d 30 20 29   if( verify==0 )
0b50: 20 62 72 65 61 6b 3b 0a 20 20 20 20 69 66 28 20   break;.    if( 
0b60: 76 65 72 69 66 79 3d 3d 31 20 26 26 20 62 6c 6f  verify==1 && blo
0b70: 62 5f 73 69 7a 65 28 70 50 61 73 73 70 68 72 61  b_size(pPassphra
0b80: 73 65 29 3d 3d 30 20 29 20 62 72 65 61 6b 3b 0a  se)==0 ) break;.
0b90: 20 20 20 20 70 72 6f 6d 70 74 5f 66 6f 72 5f 70      prompt_for_p
0ba0: 61 73 73 70 68 72 61 73 65 28 22 41 67 61 69 6e  assphrase("Again
0bb0: 3a 20 22 2c 20 26 73 65 63 6f 6e 64 54 72 79 29  : ", &secondTry)
0bc0: 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 63  ;.    if( blob_c
0bd0: 6f 6d 70 61 72 65 28 70 50 61 73 73 70 68 72 61  ompare(pPassphra
0be0: 73 65 2c 20 26 73 65 63 6f 6e 64 54 72 79 29 20  se, &secondTry) 
0bf0: 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28  ){.      printf(
0c00: 22 50 61 73 73 70 68 72 61 73 65 73 20 64 6f 20  "Passphrases do 
0c10: 6e 6f 74 20 6d 61 74 63 68 2e 20 20 54 72 79 20  not match.  Try 
0c20: 61 67 61 69 6e 2e 2e 2e 5c 6e 22 29 3b 0a 20 20  again...\n");.  
0c30: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 62    }else{.      b
0c40: 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a  reak;.    }.  }.
0c50: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 73 65    blob_reset(&se
0c60: 63 6f 6e 64 54 72 79 29 3b 0a 7d 0a 0a 2f 2a 0a  condTry);.}../*.
0c70: 2a 2a 20 50 72 6f 6d 70 74 20 74 68 65 20 75 73  ** Prompt the us
0c80: 65 72 20 74 6f 20 65 6e 74 65 72 20 61 20 73 69  er to enter a si
0c90: 6e 67 6c 65 20 6c 69 6e 65 20 6f 66 20 74 65 78  ngle line of tex
0ca0: 74 2e 0a 2a 2f 0a 76 6f 69 64 20 70 72 6f 6d 70  t..*/.void promp
0cb0: 74 5f 75 73 65 72 28 63 6f 6e 73 74 20 63 68 61  t_user(const cha
0cc0: 72 20 2a 7a 50 72 6f 6d 70 74 2c 20 42 6c 6f 62  r *zPrompt, Blob
0cd0: 20 2a 70 49 6e 29 7b 0a 20 20 63 68 61 72 20 2a   *pIn){.  char *
0ce0: 7a 3b 0a 20 20 63 68 61 72 20 7a 4c 69 6e 65 5b  z;.  char zLine[
0cf0: 31 30 30 30 5d 3b 0a 20 20 62 6c 6f 62 5f 7a 65  1000];.  blob_ze
0d00: 72 6f 28 70 49 6e 29 3b 0a 20 20 70 72 69 6e 74  ro(pIn);.  print
0d10: 66 28 22 25 73 22 2c 20 7a 50 72 6f 6d 70 74 29  f("%s", zPrompt)
0d20: 3b 0a 20 20 66 66 6c 75 73 68 28 73 74 64 6f 75  ;.  fflush(stdou
0d30: 74 29 3b 0a 20 20 7a 20 3d 20 66 67 65 74 73 28  t);.  z = fgets(
0d40: 7a 4c 69 6e 65 2c 20 73 69 7a 65 6f 66 28 7a 4c  zLine, sizeof(zL
0d50: 69 6e 65 29 2c 20 73 74 64 69 6e 29 3b 0a 20 20  ine), stdin);.  
0d60: 69 66 28 20 7a 20 29 7b 0a 20 20 20 20 73 74 72  if( z ){.    str
0d70: 69 70 5f 73 74 72 69 6e 67 28 70 49 6e 2c 20 7a  ip_string(pIn, z
0d80: 29 3b 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a  );.  }.}.../*.**
0d90: 20 43 4f 4d 4d 41 4e 44 3a 20 20 75 73 65 72 0a   COMMAND:  user.
0da0: 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f  **.** Usage: %fo
0db0: 73 73 69 6c 20 75 73 65 72 20 53 55 42 43 4f 4d  ssil user SUBCOM
0dc0: 4d 41 4e 44 20 2e 2e 2e 20 20 3f 2d 52 7c 2d 2d  MAND ...  ?-R|--
0dd0: 72 65 70 6f 73 69 74 6f 72 79 20 46 49 4c 45 3f  repository FILE?
0de0: 0a 2a 2a 0a 2a 2a 20 52 75 6e 20 76 61 72 69 6f  .**.** Run vario
0df0: 75 73 20 73 75 62 63 6f 6d 6d 61 6e 64 73 20 6f  us subcommands o
0e00: 6e 20 75 73 65 72 73 20 6f 66 20 74 68 65 20 6f  n users of the o
0e10: 70 65 6e 20 72 65 70 6f 73 69 74 6f 72 79 20 6f  pen repository o
0e20: 72 20 6f 66 0a 2a 2a 20 74 68 65 20 72 65 70 6f  r of.** the repo
0e30: 73 69 74 6f 72 79 20 69 64 65 6e 74 69 66 69 65  sitory identifie
0e40: 64 20 62 79 20 74 68 65 20 2d 52 20 6f 72 20 2d  d by the -R or -
0e50: 2d 72 65 70 6f 73 69 74 6f 72 79 20 6f 70 74 69  -repository opti
0e60: 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 25 66 6f  on..**.**    %fo
0e70: 73 73 69 6c 20 75 73 65 72 20 63 61 70 61 62 69  ssil user capabi
0e80: 6c 69 74 69 65 73 20 55 53 45 52 4e 41 4d 45 20  lities USERNAME 
0e90: 3f 53 54 52 49 4e 47 3f 0a 2a 2a 0a 2a 2a 20 20  ?STRING?.**.**  
0ea0: 20 20 20 20 20 20 51 75 65 72 79 20 6f 72 20 73        Query or s
0eb0: 65 74 20 74 68 65 20 63 61 70 61 62 69 6c 69 74  et the capabilit
0ec0: 69 65 73 20 66 6f 72 20 75 73 65 72 20 55 53 45  ies for user USE
0ed0: 52 4e 41 4d 45 0a 2a 2a 0a 2a 2a 20 20 20 20 25  RNAME.**.**    %
0ee0: 66 6f 73 73 69 6c 20 75 73 65 72 20 64 65 66 61  fossil user defa
0ef0: 75 6c 74 20 3f 55 53 45 52 4e 41 4d 45 3f 0a 2a  ult ?USERNAME?.*
0f00: 2a 0a 2a 2a 20 20 20 20 20 20 20 20 51 75 65 72  *.**        Quer
0f10: 79 20 6f 72 20 73 65 74 20 74 68 65 20 64 65 66  y or set the def
0f20: 61 75 6c 74 20 75 73 65 72 2e 20 20 54 68 65 20  ault user.  The 
0f30: 64 65 66 61 75 6c 74 20 75 73 65 72 20 69 73 20  default user is 
0f40: 74 68 65 0a 2a 2a 20 20 20 20 20 20 20 20 75 73  the.**        us
0f50: 65 72 20 66 6f 72 20 63 6f 6d 6d 61 6e 64 2d 6c  er for command-l
0f60: 69 6e 65 20 69 6e 74 65 72 61 63 74 69 6f 6e 2e  ine interaction.
0f70: 0a 2a 2a 0a 2a 2a 20 20 20 20 25 66 6f 73 73 69  .**.**    %fossi
0f80: 6c 20 75 73 65 72 20 6c 69 73 74 0a 2a 2a 0a 2a  l user list.**.*
0f90: 2a 20 20 20 20 20 20 20 20 4c 69 73 74 20 61 6c  *        List al
0fa0: 6c 20 75 73 65 72 73 20 6b 6e 6f 77 6e 20 74 6f  l users known to
0fb0: 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 0a   the repository.
0fc0: 2a 2a 0a 2a 2a 20 20 20 20 25 66 6f 73 73 69 6c  **.**    %fossil
0fd0: 20 75 73 65 72 20 6e 65 77 0a 2a 2a 0a 2a 2a 20   user new.**.** 
0fe0: 20 20 20 20 20 20 20 43 72 65 61 74 65 20 61 20         Create a 
0ff0: 6e 65 77 20 75 73 65 72 20 69 6e 20 74 68 65 20  new user in the 
1000: 72 65 70 6f 73 69 74 6f 72 79 2e 20 20 55 73 65  repository.  Use
1010: 72 73 20 63 61 6e 20 6e 65 76 65 72 20 62 65 0a  rs can never be.
1020: 2a 2a 20 20 20 20 20 20 20 20 64 65 6c 65 74 65  **        delete
1030: 64 2e 20 20 54 68 65 79 20 63 61 6e 20 62 65 20  d.  They can be 
1040: 64 65 6e 69 65 64 20 61 6c 6c 20 61 63 63 65 73  denied all acces
1050: 73 20 62 75 74 20 74 68 65 79 20 6d 75 73 74 20  s but they must 
1060: 63 6f 6e 74 69 6e 75 65 0a 2a 2a 20 20 20 20 20  continue.**     
1070: 20 20 20 74 6f 20 65 78 69 73 74 20 69 6e 20 74     to exist in t
1080: 68 65 20 64 61 74 61 62 61 73 65 2e 0a 2a 2a 0a  he database..**.
1090: 2a 2a 20 20 20 20 25 66 6f 73 73 69 6c 20 75 73  **    %fossil us
10a0: 65 72 20 70 61 73 73 77 6f 72 64 20 55 53 45 52  er password USER
10b0: 4e 41 4d 45 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20  NAME.**.**      
10c0: 20 20 43 68 61 6e 67 65 20 74 68 65 20 77 65 62    Change the web
10d0: 20 61 63 63 65 73 73 20 70 61 73 73 77 6f 72 64   access password
10e0: 20 66 6f 72 20 61 20 75 73 65 72 2e 0a 2a 2f 0a   for a user..*/.
10f0: 76 6f 69 64 20 75 73 65 72 5f 63 6d 64 28 76 6f  void user_cmd(vo
1100: 69 64 29 7b 0a 20 20 69 6e 74 20 6e 3b 0a 20 20  id){.  int n;.  
1110: 64 62 5f 66 69 6e 64 5f 61 6e 64 5f 6f 70 65 6e  db_find_and_open
1120: 5f 72 65 70 6f 73 69 74 6f 72 79 28 29 3b 0a 20  _repository();. 
1130: 20 69 66 28 20 67 2e 61 72 67 63 3c 33 20 29 7b   if( g.argc<3 ){
1140: 0a 20 20 20 20 75 73 61 67 65 28 22 63 61 70 61  .    usage("capa
1150: 62 69 6c 69 74 69 65 73 7c 64 65 66 61 75 6c 74  bilities|default
1160: 7c 6c 69 73 74 7c 6e 65 77 7c 70 61 73 73 77 6f  |list|new|passwo
1170: 72 64 20 2e 2e 2e 22 29 3b 0a 20 20 7d 0a 20 20  rd ...");.  }.  
1180: 6e 20 3d 20 73 74 72 6c 65 6e 28 67 2e 61 72 67  n = strlen(g.arg
1190: 76 5b 32 5d 29 3b 0a 20 20 69 66 28 20 6e 3e 3d  v[2]);.  if( n>=
11a0: 32 20 26 26 20 73 74 72 6e 63 6d 70 28 67 2e 61  2 && strncmp(g.a
11b0: 72 67 76 5b 32 5d 2c 22 6e 65 77 22 2c 6e 29 3d  rgv[2],"new",n)=
11c0: 3d 30 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 70  =0 ){.    Blob p
11d0: 61 73 73 77 64 2c 20 6c 6f 67 69 6e 2c 20 63 6f  asswd, login, co
11e0: 6e 74 61 63 74 3b 0a 0a 20 20 20 20 70 72 6f 6d  ntact;..    prom
11f0: 70 74 5f 75 73 65 72 28 22 6c 6f 67 69 6e 3a 20  pt_user("login: 
1200: 22 2c 20 26 6c 6f 67 69 6e 29 3b 0a 20 20 20 20  ", &login);.    
1210: 70 72 6f 6d 70 74 5f 75 73 65 72 28 22 63 6f 6e  prompt_user("con
1220: 74 61 63 74 2d 69 6e 66 6f 3a 20 22 2c 20 26 63  tact-info: ", &c
1230: 6f 6e 74 61 63 74 29 3b 0a 20 20 20 20 70 72 6f  ontact);.    pro
1240: 6d 70 74 5f 66 6f 72 5f 70 61 73 73 77 6f 72 64  mpt_for_password
1250: 28 22 70 61 73 73 77 6f 72 64 3a 20 22 2c 20 26  ("password: ", &
1260: 70 61 73 73 77 64 2c 20 31 29 3b 0a 20 20 20 20  passwd, 1);.    
1270: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20  db_multi_exec(. 
1280: 20 20 20 20 20 22 49 4e 53 45 52 54 20 49 4e 54       "INSERT INT
1290: 4f 20 75 73 65 72 28 6c 6f 67 69 6e 2c 70 77 2c  O user(login,pw,
12a0: 63 61 70 2c 69 6e 66 6f 29 22 0a 20 20 20 20 20  cap,info)".     
12b0: 20 22 56 41 4c 55 45 53 28 25 42 2c 25 42 2c 27   "VALUES(%B,%B,'
12c0: 6a 6e 6f 72 27 2c 25 42 29 22 2c 0a 20 20 20 20  jnor',%B)",.    
12d0: 20 20 26 6c 6f 67 69 6e 2c 20 26 70 61 73 73 77    &login, &passw
12e0: 64 2c 20 26 63 6f 6e 74 61 63 74 0a 20 20 20 20  d, &contact.    
12f0: 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 6e  );.  }else if( n
1300: 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d 70 28 67  >=2 && strncmp(g
1310: 2e 61 72 67 76 5b 32 5d 2c 22 64 65 66 61 75 6c  .argv[2],"defaul
1320: 74 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20  t",n)==0 ){.    
1330: 75 73 65 72 5f 73 65 6c 65 63 74 28 29 3b 0a 20  user_select();. 
1340: 20 20 20 69 66 28 20 67 2e 61 72 67 63 3d 3d 33     if( g.argc==3
1350: 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66   ){.      printf
1360: 28 22 25 73 5c 6e 22 2c 20 67 2e 7a 4c 6f 67 69  ("%s\n", g.zLogi
1370: 6e 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66  n);.    }else if
1380: 28 20 67 2e 6c 6f 63 61 6c 4f 70 65 6e 20 29 7b  ( g.localOpen ){
1390: 0a 20 20 20 20 20 20 64 62 5f 6c 73 65 74 28 22  .      db_lset("
13a0: 64 65 66 61 75 6c 74 2d 75 73 65 72 22 2c 20 67  default-user", g
13b0: 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20 20 20 7d 65  .zLogin);.    }e
13c0: 6c 73 65 7b 0a 20 20 20 20 20 20 64 62 5f 73 65  lse{.      db_se
13d0: 74 28 22 64 65 66 61 75 6c 74 2d 75 73 65 72 22  t("default-user"
13e0: 2c 20 67 2e 7a 4c 6f 67 69 6e 2c 20 30 29 3b 0a  , g.zLogin, 0);.
13f0: 20 20 20 20 7d 0a 20 20 7d 65 6c 73 65 20 69 66      }.  }else if
1400: 28 20 6e 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d  ( n>=2 && strncm
1410: 70 28 67 2e 61 72 67 76 5b 32 5d 2c 22 6c 69 73  p(g.argv[2],"lis
1420: 74 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20  t",n)==0 ){.    
1430: 53 74 6d 74 20 71 3b 0a 20 20 20 20 64 62 5f 70  Stmt q;.    db_p
1440: 72 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45  repare(&q, "SELE
1450: 43 54 20 6c 6f 67 69 6e 2c 20 69 6e 66 6f 20 46  CT login, info F
1460: 52 4f 4d 20 75 73 65 72 20 4f 52 44 45 52 20 42  ROM user ORDER B
1470: 59 20 6c 6f 67 69 6e 22 29 3b 0a 20 20 20 20 77  Y login");.    w
1480: 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71  hile( db_step(&q
1490: 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b  )==SQLITE_ROW ){
14a0: 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 25  .      printf("%
14b0: 2d 31 32 73 20 25 73 5c 6e 22 2c 20 64 62 5f 63  -12s %s\n", db_c
14c0: 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30  olumn_text(&q, 0
14d0: 29 2c 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78  ), db_column_tex
14e0: 74 28 26 71 2c 20 31 29 29 3b 0a 20 20 20 20 7d  t(&q, 1));.    }
14f0: 0a 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65  .    db_finalize
1500: 28 26 71 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66  (&q);.  }else if
1510: 28 20 6e 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d  ( n>=2 && strncm
1520: 70 28 67 2e 61 72 67 76 5b 32 5d 2c 22 70 61 73  p(g.argv[2],"pas
1530: 73 77 6f 72 64 22 2c 32 29 3d 3d 30 20 29 7b 0a  sword",2)==0 ){.
1540: 20 20 20 20 63 68 61 72 20 2a 7a 50 72 6f 6d 70      char *zPromp
1550: 74 3b 0a 20 20 20 20 69 6e 74 20 75 69 64 3b 0a  t;.    int uid;.
1560: 20 20 20 20 42 6c 6f 62 20 70 77 3b 0a 20 20 20      Blob pw;.   
1570: 20 69 66 28 20 67 2e 61 72 67 63 21 3d 34 20 29   if( g.argc!=4 )
1580: 20 75 73 61 67 65 28 22 70 61 73 73 77 6f 72 64   usage("password
1590: 20 55 53 45 52 4e 41 4d 45 22 29 3b 0a 20 20 20   USERNAME");.   
15a0: 20 75 69 64 20 3d 20 64 62 5f 69 6e 74 28 30 2c   uid = db_int(0,
15b0: 20 22 53 45 4c 45 43 54 20 75 69 64 20 46 52 4f   "SELECT uid FRO
15c0: 4d 20 75 73 65 72 20 57 48 45 52 45 20 6c 6f 67  M user WHERE log
15d0: 69 6e 3d 25 51 22 2c 20 67 2e 61 72 67 76 5b 33  in=%Q", g.argv[3
15e0: 5d 29 3b 0a 20 20 20 20 69 66 28 20 75 69 64 3d  ]);.    if( uid=
15f0: 3d 30 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73  =0 ){.      foss
1600: 69 6c 5f 66 61 74 61 6c 28 22 6e 6f 20 73 75 63  il_fatal("no suc
1610: 68 20 75 73 65 72 3a 20 25 73 22 2c 20 67 2e 61  h user: %s", g.a
1620: 72 67 76 5b 33 5d 29 3b 0a 20 20 20 20 7d 0a 20  rgv[3]);.    }. 
1630: 20 20 20 7a 50 72 6f 6d 70 74 20 3d 20 6d 70 72     zPrompt = mpr
1640: 69 6e 74 66 28 22 6e 65 77 20 70 61 73 73 77 64  intf("new passwd
1650: 20 66 6f 72 20 25 73 3a 20 22 2c 20 67 2e 61 72   for %s: ", g.ar
1660: 67 76 5b 33 5d 29 3b 0a 20 20 20 20 70 72 6f 6d  gv[3]);.    prom
1670: 70 74 5f 66 6f 72 5f 70 61 73 73 77 6f 72 64 28  pt_for_password(
1680: 7a 50 72 6f 6d 70 74 2c 20 26 70 77 2c 20 31 29  zPrompt, &pw, 1)
1690: 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 73  ;.    if( blob_s
16a0: 69 7a 65 28 26 70 77 29 3d 3d 30 20 29 7b 0a 20  ize(&pw)==0 ){. 
16b0: 20 20 20 20 20 70 72 69 6e 74 66 28 22 70 61 73       printf("pas
16c0: 73 77 6f 72 64 20 75 6e 63 68 61 6e 67 65 64 5c  sword unchanged\
16d0: 6e 22 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a  n");.    }else{.
16e0: 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65        db_multi_e
16f0: 78 65 63 28 22 55 50 44 41 54 45 20 75 73 65 72  xec("UPDATE user
1700: 20 53 45 54 20 70 77 3d 25 42 20 57 48 45 52 45   SET pw=%B WHERE
1710: 20 75 69 64 3d 25 64 22 2c 20 26 70 77 2c 20 75   uid=%d", &pw, u
1720: 69 64 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65 6c  id);.    }.  }el
1730: 73 65 20 69 66 28 20 6e 3e 3d 32 20 26 26 20 73  se if( n>=2 && s
1740: 74 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d  trncmp(g.argv[2]
1750: 2c 22 63 61 70 61 62 69 6c 69 74 69 65 73 22 2c  ,"capabilities",
1760: 32 29 3d 3d 30 20 29 7b 0a 20 20 20 20 69 6e 74  2)==0 ){.    int
1770: 20 75 69 64 3b 0a 20 20 20 20 69 66 28 20 67 2e   uid;.    if( g.
1780: 61 72 67 63 21 3d 34 20 26 26 20 67 2e 61 72 67  argc!=4 && g.arg
1790: 63 21 3d 35 20 29 7b 0a 20 20 20 20 20 20 75 73  c!=5 ){.      us
17a0: 61 67 65 28 22 75 73 65 72 20 63 61 70 61 62 69  age("user capabi
17b0: 6c 69 74 69 65 73 20 55 53 45 52 4e 41 4d 45 20  lities USERNAME 
17c0: 3f 50 45 52 4d 49 53 53 49 4f 4e 53 3f 22 29 3b  ?PERMISSIONS?");
17d0: 0a 20 20 20 20 7d 0a 20 20 20 20 75 69 64 20 3d  .    }.    uid =
17e0: 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45   db_int(0, "SELE
17f0: 43 54 20 75 69 64 20 46 52 4f 4d 20 75 73 65 72  CT uid FROM user
1800: 20 57 48 45 52 45 20 6c 6f 67 69 6e 3d 25 51 22   WHERE login=%Q"
1810: 2c 20 67 2e 61 72 67 76 5b 33 5d 29 3b 0a 20 20  , g.argv[3]);.  
1820: 20 20 69 66 28 20 75 69 64 3d 3d 30 20 29 7b 0a    if( uid==0 ){.
1830: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74        fossil_fat
1840: 61 6c 28 22 6e 6f 20 73 75 63 68 20 75 73 65 72  al("no such user
1850: 3a 20 25 73 22 2c 20 67 2e 61 72 67 76 5b 33 5d  : %s", g.argv[3]
1860: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28  );.    }.    if(
1870: 20 67 2e 61 72 67 63 3d 3d 35 20 29 7b 0a 20 20   g.argc==5 ){.  
1880: 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65      db_multi_exe
1890: 63 28 0a 20 20 20 20 20 20 20 20 22 55 50 44 41  c(.        "UPDA
18a0: 54 45 20 75 73 65 72 20 53 45 54 20 63 61 70 3d  TE user SET cap=
18b0: 25 51 20 57 48 45 52 45 20 75 69 64 3d 25 64 22  %Q WHERE uid=%d"
18c0: 2c 20 67 2e 61 72 67 76 5b 34 5d 2c 0a 20 20 20  , g.argv[4],.   
18d0: 20 20 20 20 20 75 69 64 0a 20 20 20 20 20 20 29       uid.      )
18e0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 70 72 69 6e  ;.    }.    prin
18f0: 74 66 28 22 25 73 5c 6e 22 2c 20 64 62 5f 74 65  tf("%s\n", db_te
1900: 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 63 61  xt(0, "SELECT ca
1910: 70 20 46 52 4f 4d 20 75 73 65 72 20 57 48 45 52  p FROM user WHER
1920: 45 20 75 69 64 3d 25 64 22 2c 20 75 69 64 29 29  E uid=%d", uid))
1930: 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 66  ;.  }else{.    f
1940: 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 75 73 65  ossil_panic("use
1950: 72 20 73 75 62 63 6f 6d 6d 61 6e 64 20 73 68 6f  r subcommand sho
1960: 75 6c 64 20 62 65 20 6f 6e 65 20 6f 66 3a 20 22  uld be one of: "
1970: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
1980: 20 20 22 63 61 70 61 62 69 6c 69 74 69 65 73 20    "capabilities 
1990: 64 65 66 61 75 6c 74 20 6c 69 73 74 20 6e 65 77  default list new
19a0: 20 70 61 73 73 77 6f 72 64 22 29 3b 0a 20 20 7d   password");.  }
19b0: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 41 74 74 65 6d 70  .}../*.** Attemp
19c0: 74 20 74 6f 20 73 65 74 20 74 68 65 20 75 73 65  t to set the use
19d0: 72 20 74 6f 20 7a 4c 6f 67 69 6e 0a 2a 2f 0a 73  r to zLogin.*/.s
19e0: 74 61 74 69 63 20 69 6e 74 20 61 74 74 65 6d 70  tatic int attemp
19f0: 74 5f 75 73 65 72 28 63 6f 6e 73 74 20 63 68 61  t_user(const cha
1a00: 72 20 2a 7a 4c 6f 67 69 6e 29 7b 0a 20 20 69 6e  r *zLogin){.  in
1a10: 74 20 75 69 64 3b 0a 0a 20 20 69 66 28 20 7a 4c  t uid;..  if( zL
1a20: 6f 67 69 6e 3d 3d 30 20 29 7b 0a 20 20 20 20 72  ogin==0 ){.    r
1a30: 65 74 75 72 6e 20 30 3b 0a 20 20 7d 0a 20 20 75  eturn 0;.  }.  u
1a40: 69 64 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22  id = db_int(0, "
1a50: 53 45 4c 45 43 54 20 75 69 64 20 46 52 4f 4d 20  SELECT uid FROM 
1a60: 75 73 65 72 20 57 48 45 52 45 20 6c 6f 67 69 6e  user WHERE login
1a70: 3d 25 51 22 2c 20 7a 4c 6f 67 69 6e 29 3b 0a 20  =%Q", zLogin);. 
1a80: 20 69 66 28 20 75 69 64 20 29 7b 0a 20 20 20 20   if( uid ){.    
1a90: 67 2e 75 73 65 72 55 69 64 20 3d 20 75 69 64 3b  g.userUid = uid;
1aa0: 0a 20 20 20 20 67 2e 7a 4c 6f 67 69 6e 20 3d 20  .    g.zLogin = 
1ab0: 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 7a 4c  mprintf("%s", zL
1ac0: 6f 67 69 6e 29 3b 0a 20 20 20 20 72 65 74 75 72  ogin);.    retur
1ad0: 6e 20 31 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72  n 1;.  }.  retur
1ae0: 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 46 69  n 0;.}../*.** Fi
1af0: 67 75 72 65 20 6f 75 74 20 77 68 61 74 20 75 73  gure out what us
1b00: 65 72 20 69 73 20 61 74 20 74 68 65 20 63 6f 6e  er is at the con
1b10: 74 72 6f 6c 73 2e 0a 2a 2a 0a 2a 2a 20 20 20 28  trols..**.**   (
1b20: 31 29 20 20 55 73 65 20 74 68 65 20 2d 2d 75 73  1)  Use the --us
1b30: 65 72 20 61 6e 64 20 2d 55 20 63 6f 6d 6d 61 6e  er and -U comman
1b40: 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e 73 2e 0a  d-line options..
1b50: 2a 2a 0a 2a 2a 20 20 20 28 32 29 20 20 49 66 20  **.**   (2)  If 
1b60: 74 68 65 20 6c 6f 63 61 6c 20 64 61 74 61 62 61  the local databa
1b70: 73 65 20 69 73 20 6f 70 65 6e 2c 20 63 68 65 63  se is open, chec
1b80: 6b 20 69 6e 20 56 56 41 52 2e 0a 2a 2a 0a 2a 2a  k in VVAR..**.**
1b90: 20 20 20 28 33 29 20 20 43 68 65 63 6b 20 74 68     (3)  Check th
1ba0: 65 20 64 65 66 61 75 6c 74 20 75 73 65 72 20 69  e default user i
1bb0: 6e 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79  n the repository
1bc0: 0a 2a 2a 0a 2a 2a 20 20 20 28 34 29 20 20 54 72  .**.**   (4)  Tr
1bd0: 79 20 74 68 65 20 55 53 45 52 20 65 6e 76 69 72  y the USER envir
1be0: 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 2e  onment variable.
1bf0: 0a 2a 2a 0a 2a 2a 20 20 20 28 35 29 20 20 55 73  .**.**   (5)  Us
1c00: 65 20 74 68 65 20 66 69 72 73 74 20 75 73 65 72  e the first user
1c10: 20 69 6e 20 74 68 65 20 55 53 45 52 20 74 61 62   in the USER tab
1c20: 6c 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 75 73  le..**.** The us
1c30: 65 72 20 6e 61 6d 65 20 69 73 20 73 74 6f 72 65  er name is store
1c40: 64 20 69 6e 20 67 2e 7a 4c 6f 67 69 6e 2e 20 20  d in g.zLogin.  
1c50: 54 68 65 20 75 69 64 20 69 73 20 69 6e 20 67 2e  The uid is in g.
1c60: 75 73 65 72 55 69 64 2e 0a 2a 2f 0a 76 6f 69 64  userUid..*/.void
1c70: 20 75 73 65 72 5f 73 65 6c 65 63 74 28 76 6f 69   user_select(voi
1c80: 64 29 7b 0a 20 20 53 74 6d 74 20 73 3b 0a 0a 20  d){.  Stmt s;.. 
1c90: 20 69 66 28 20 67 2e 75 73 65 72 55 69 64 20 29   if( g.userUid )
1ca0: 20 72 65 74 75 72 6e 3b 0a 20 20 69 66 28 20 61   return;.  if( a
1cb0: 74 74 65 6d 70 74 5f 75 73 65 72 28 67 2e 7a 4c  ttempt_user(g.zL
1cc0: 6f 67 69 6e 29 20 29 20 72 65 74 75 72 6e 3b 0a  ogin) ) return;.
1cd0: 0a 20 20 69 66 28 20 67 2e 6c 6f 63 61 6c 4f 70  .  if( g.localOp
1ce0: 65 6e 20 26 26 20 61 74 74 65 6d 70 74 5f 75 73  en && attempt_us
1cf0: 65 72 28 64 62 5f 6c 67 65 74 28 22 64 65 66 61  er(db_lget("defa
1d00: 75 6c 74 2d 75 73 65 72 22 2c 30 29 29 20 29 20  ult-user",0)) ) 
1d10: 72 65 74 75 72 6e 3b 0a 0a 20 20 69 66 28 20 61  return;..  if( a
1d20: 74 74 65 6d 70 74 5f 75 73 65 72 28 64 62 5f 67  ttempt_user(db_g
1d30: 65 74 28 22 64 65 66 61 75 6c 74 2d 75 73 65 72  et("default-user
1d40: 22 2c 20 30 29 29 20 29 20 72 65 74 75 72 6e 3b  ", 0)) ) return;
1d50: 0a 0a 20 20 69 66 28 20 61 74 74 65 6d 70 74 5f  ..  if( attempt_
1d60: 75 73 65 72 28 67 65 74 65 6e 76 28 22 55 53 45  user(getenv("USE
1d70: 52 22 29 29 20 29 20 72 65 74 75 72 6e 3b 0a 0a  R")) ) return;..
1d80: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 73 2c    db_prepare(&s,
1d90: 20 22 53 45 4c 45 43 54 20 75 69 64 2c 20 6c 6f   "SELECT uid, lo
1da0: 67 69 6e 20 46 52 4f 4d 20 75 73 65 72 22 0a 20  gin FROM user". 
1db0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1dc0: 22 20 57 48 45 52 45 20 6c 6f 67 69 6e 20 4e 4f  " WHERE login NO
1dd0: 54 20 49 4e 20 28 27 61 6e 6f 6e 79 6d 6f 75 73  T IN ('anonymous
1de0: 27 2c 27 6e 6f 62 6f 64 79 27 29 22 29 3b 0a 20  ','nobody')");. 
1df0: 20 69 66 28 20 64 62 5f 73 74 65 70 28 26 73 29   if( db_step(&s)
1e00: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a  ==SQLITE_ROW ){.
1e10: 20 20 20 20 67 2e 75 73 65 72 55 69 64 20 3d 20      g.userUid = 
1e20: 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 73  db_column_int(&s
1e30: 2c 20 30 29 3b 0a 20 20 20 20 67 2e 7a 4c 6f 67  , 0);.    g.zLog
1e40: 69 6e 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73  in = mprintf("%s
1e50: 22 2c 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78  ", db_column_tex
1e60: 74 28 26 73 2c 20 31 29 29 3b 0a 20 20 7d 0a 20  t(&s, 1));.  }. 
1e70: 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 73 29   db_finalize(&s)
1e80: 3b 0a 0a 20 20 69 66 28 20 67 2e 75 73 65 72 55  ;..  if( g.userU
1e90: 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 64 62 5f  id==0 ){.    db_
1ea0: 70 72 65 70 61 72 65 28 26 73 2c 20 22 53 45 4c  prepare(&s, "SEL
1eb0: 45 43 54 20 75 69 64 2c 20 6c 6f 67 69 6e 20 46  ECT uid, login F
1ec0: 52 4f 4d 20 75 73 65 72 22 29 3b 0a 20 20 20 20  ROM user");.    
1ed0: 69 66 28 20 64 62 5f 73 74 65 70 28 26 73 29 3d  if( db_step(&s)=
1ee0: 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20  =SQLITE_ROW ){. 
1ef0: 20 20 20 20 20 67 2e 75 73 65 72 55 69 64 20 3d       g.userUid =
1f00: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26   db_column_int(&
1f10: 73 2c 20 30 29 3b 0a 20 20 20 20 20 20 67 2e 7a  s, 0);.      g.z
1f20: 4c 6f 67 69 6e 20 3d 20 6d 70 72 69 6e 74 66 28  Login = mprintf(
1f30: 22 25 73 22 2c 20 64 62 5f 63 6f 6c 75 6d 6e 5f  "%s", db_column_
1f40: 74 65 78 74 28 26 73 2c 20 31 29 29 3b 0a 20 20  text(&s, 1));.  
1f50: 20 20 7d 0a 20 20 20 20 64 62 5f 66 69 6e 61 6c    }.    db_final
1f60: 69 7a 65 28 26 73 29 3b 0a 20 20 7d 0a 0a 20 20  ize(&s);.  }..  
1f70: 69 66 28 20 67 2e 75 73 65 72 55 69 64 3d 3d 30  if( g.userUid==0
1f80: 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69   ){.    db_multi
1f90: 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 49 4e  _exec(.      "IN
1fa0: 53 45 52 54 20 49 4e 54 4f 20 75 73 65 72 28 6c  SERT INTO user(l
1fb0: 6f 67 69 6e 2c 20 70 77 2c 20 63 61 70 2c 20 69  ogin, pw, cap, i
1fc0: 6e 66 6f 29 22 0a 20 20 20 20 20 20 22 56 41 4c  nfo)".      "VAL
1fd0: 55 45 53 28 27 61 6e 6f 6e 79 6d 6f 75 73 27 2c  UES('anonymous',
1fe0: 20 27 27 2c 20 27 63 66 67 68 6a 6b 6d 6e 6f 71   '', 'cfghjkmnoq
1ff0: 77 27 2c 20 27 27 29 22 0a 20 20 20 20 29 3b 0a  w', '')".    );.
2000: 20 20 20 20 67 2e 75 73 65 72 55 69 64 20 3d 20      g.userUid = 
2010: 64 62 5f 6c 61 73 74 5f 69 6e 73 65 72 74 5f 72  db_last_insert_r
2020: 6f 77 69 64 28 29 3b 0a 20 20 20 20 67 2e 7a 4c  owid();.    g.zL
2030: 6f 67 69 6e 20 3d 20 22 61 6e 6f 6e 79 6d 6f 75  ogin = "anonymou
2040: 73 22 3b 0a 20 20 7d 0a 7d 0a                    s";.  }.}.