Hex Artifact Content
Not logged in

Artifact 47ac33e64aa0213e1e87091f5d293879c7dfc719:

File src/user.c part of check-in [e621b6dbe3] - Use POST instead of GET for the /xfer method. Other bug fixes in the URL parser. by drh on 2007-07-30 14:28:17.

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 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0310: 0a 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 2a  ****************
0360: 0a 2a 2a 0a 2a 2a 20 43 6f 6d 6d 61 6e 64 73 20  .**.** Commands 
0370: 61 6e 64 20 70 72 6f 63 65 64 75 72 65 73 20 75  and procedures u
0380: 73 65 64 20 66 6f 72 20 63 72 65 61 74 69 6e 67  sed for creating
0390: 2c 20 70 72 6f 63 65 73 73 69 6e 67 2c 20 65 64  , processing, ed
03a0: 69 74 69 6e 67 2c 20 61 6e 64 0a 2a 2a 20 71 75  iting, and.** qu
03b0: 65 72 79 69 6e 67 20 69 6e 66 6f 72 6d 61 74 69  erying informati
03c0: 6f 6e 20 61 62 6f 75 74 20 75 73 65 72 73 2e 0a  on about users..
03d0: 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e  */.#include "con
03e0: 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20  fig.h".#include 
03f0: 22 75 73 65 72 2e 68 22 0a 0a 0a 2f 2a 0a 2a 2a  "user.h".../*.**
0400: 20 53 74 72 69 70 20 6c 65 61 64 69 6e 67 20 61   Strip leading a
0410: 6e 64 20 74 72 61 69 6c 69 6e 67 20 73 70 61 63  nd trailing spac
0420: 65 20 66 72 6f 6d 20 61 20 73 74 72 69 6e 67 20  e from a string 
0430: 61 6e 64 20 61 64 64 20 74 68 65 20 73 74 72 69  and add the stri
0440: 6e 67 0a 2a 2a 20 6f 6e 74 6f 20 74 68 65 20 65  ng.** onto the e
0450: 6e 64 20 6f 66 20 61 20 62 6c 6f 62 2e 0a 2a 2f  nd of a blob..*/
0460: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 73 74 72  .static void str
0470: 69 70 5f 73 74 72 69 6e 67 28 42 6c 6f 62 20 2a  ip_string(Blob *
0480: 70 42 6c 6f 62 2c 20 63 68 61 72 20 2a 7a 29 7b  pBlob, char *z){
0490: 0a 20 20 69 6e 74 20 69 3b 0a 20 20 62 6c 6f 62  .  int i;.  blob
04a0: 5f 72 65 73 65 74 28 70 42 6c 6f 62 29 3b 0a 20  _reset(pBlob);. 
04b0: 20 77 68 69 6c 65 28 20 69 73 73 70 61 63 65 28   while( isspace(
04c0: 2a 7a 29 20 29 7b 20 7a 2b 2b 3b 20 7d 0a 20 20  *z) ){ z++; }.  
04d0: 66 6f 72 28 69 3d 30 3b 20 7a 5b 69 5d 3b 20 69  for(i=0; z[i]; i
04e0: 2b 2b 29 7b 0a 20 20 20 20 69 66 28 20 7a 5b 69  ++){.    if( z[i
04f0: 5d 3d 3d 27 5c 72 27 20 7c 7c 20 7a 5b 69 5d 3d  ]=='\r' || z[i]=
0500: 3d 27 5c 6e 27 20 29 7b 0a 20 20 20 20 20 20 20  ='\n' ){.       
0510: 77 68 69 6c 65 28 20 69 3e 30 20 26 26 20 69 73  while( i>0 && is
0520: 73 70 61 63 65 28 7a 5b 69 2d 31 5d 29 20 29 7b  space(z[i-1]) ){
0530: 20 69 2d 2d 3b 20 7d 0a 20 20 20 20 20 20 20 7a   i--; }.       z
0540: 5b 69 5d 20 3d 20 30 3b 0a 20 20 20 20 20 20 20  [i] = 0;.       
0550: 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 20  break;.    }.   
0560: 20 69 66 28 20 7a 5b 69 5d 3c 27 20 27 20 29 20   if( z[i]<' ' ) 
0570: 7a 5b 69 5d 20 3d 20 27 20 27 3b 0a 20 20 7d 0a  z[i] = ' ';.  }.
0580: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 42    blob_append(pB
0590: 6c 6f 62 2c 20 7a 2c 20 2d 31 29 3b 0a 7d 0a 0a  lob, z, -1);.}..
05a0: 2f 2a 0a 2a 2a 20 44 6f 20 61 20 73 69 6e 67 6c  /*.** Do a singl
05b0: 65 20 70 72 6f 6d 70 74 20 66 6f 72 20 61 20 70  e prompt for a p
05c0: 61 73 73 70 68 72 61 73 65 2e 20 20 53 74 6f 72  assphrase.  Stor
05d0: 65 20 74 68 65 20 72 65 73 75 6c 74 73 20 69 6e  e the results in
05e0: 20 74 68 65 20 62 6c 6f 62 2e 0a 2a 2f 0a 73 74   the blob..*/.st
05f0: 61 74 69 63 20 76 6f 69 64 20 70 72 6f 6d 70 74  atic void prompt
0600: 5f 66 6f 72 5f 70 61 73 73 70 68 72 61 73 65 28  _for_passphrase(
0610: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 72 6f  const char *zPro
0620: 6d 70 74 2c 20 42 6c 6f 62 20 2a 70 50 61 73 73  mpt, Blob *pPass
0630: 70 68 72 61 73 65 29 7b 0a 20 20 63 68 61 72 20  phrase){.  char 
0640: 2a 7a 20 3d 20 67 65 74 70 61 73 73 28 7a 50 72  *z = getpass(zPr
0650: 6f 6d 70 74 29 3b 0a 20 20 73 74 72 69 70 5f 73  ompt);.  strip_s
0660: 74 72 69 6e 67 28 70 50 61 73 73 70 68 72 61 73  tring(pPassphras
0670: 65 2c 20 7a 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  e, z);.}../*.** 
0680: 50 72 6f 6d 70 74 20 74 68 65 20 75 73 65 72 20  Prompt the user 
0690: 66 6f 72 20 61 20 70 61 73 73 77 6f 72 64 2e 20  for a password. 
06a0: 20 53 74 6f 72 65 20 74 68 65 20 72 65 73 75 6c   Store the resul
06b0: 74 20 69 6e 20 74 68 65 20 70 50 61 73 73 70 68  t in the pPassph
06c0: 72 61 73 65 0a 2a 2a 20 62 6c 6f 62 2e 0a 2a 2a  rase.** blob..**
06d0: 0a 2a 2a 20 42 65 68 61 76 69 6f 72 20 69 73 20  .** Behavior is 
06e0: 63 6f 6e 74 72 6f 6c 6c 65 64 20 62 79 20 74 68  controlled by th
06f0: 65 20 76 65 72 69 66 79 20 70 61 72 61 6d 65 74  e verify paramet
0700: 65 72 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 30 20  er:.**.**     0 
0710: 20 20 20 20 4a 75 73 74 20 61 73 6b 20 6f 6e 63      Just ask onc
0720: 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 31 20 20  e..**.**     1  
0730: 20 20 20 49 66 20 74 68 65 20 66 69 72 73 74 20     If the first 
0740: 61 6e 73 77 65 72 20 69 73 20 61 20 6e 6f 6e 2d  answer is a non-
0750: 65 6d 70 74 79 20 73 74 72 69 6e 67 2c 20 61 73  empty string, as
0760: 6b 20 66 6f 72 0a 2a 2a 20 20 20 20 20 20 20 20  k for.**        
0770: 20 20 20 76 65 72 69 66 69 63 61 74 69 6f 6e 2e     verification.
0780: 20 20 52 65 70 65 61 74 20 69 66 20 74 68 65 20    Repeat if the 
0790: 74 77 6f 20 73 74 72 69 6e 67 73 20 64 6f 20 6e  two strings do n
07a0: 6f 74 20 6d 61 74 63 68 2e 0a 2a 2a 0a 2a 2a 20  ot match..**.** 
07b0: 20 20 20 20 32 20 20 20 20 20 41 73 6b 20 74 77      2     Ask tw
07c0: 69 63 65 2c 20 72 65 70 65 61 74 20 69 66 20 74  ice, repeat if t
07d0: 68 65 20 73 74 72 69 6e 67 73 20 64 6f 20 6e 6f  he strings do no
07e0: 74 20 6d 61 74 63 68 2e 0a 2a 2f 0a 76 6f 69 64  t match..*/.void
07f0: 20 70 72 6f 6d 70 74 5f 66 6f 72 5f 70 61 73 73   prompt_for_pass
0800: 77 6f 72 64 28 0a 20 20 63 6f 6e 73 74 20 63 68  word(.  const ch
0810: 61 72 20 2a 7a 50 72 6f 6d 70 74 2c 0a 20 20 42  ar *zPrompt,.  B
0820: 6c 6f 62 20 2a 70 50 61 73 73 70 68 72 61 73 65  lob *pPassphrase
0830: 2c 0a 20 20 69 6e 74 20 76 65 72 69 66 79 0a 29  ,.  int verify.)
0840: 7b 0a 20 20 42 6c 6f 62 20 73 65 63 6f 6e 64 54  {.  Blob secondT
0850: 72 79 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28  ry;.  blob_zero(
0860: 70 50 61 73 73 70 68 72 61 73 65 29 3b 0a 20 20  pPassphrase);.  
0870: 62 6c 6f 62 5f 7a 65 72 6f 28 26 73 65 63 6f 6e  blob_zero(&secon
0880: 64 54 72 79 29 3b 0a 20 20 77 68 69 6c 65 28 31  dTry);.  while(1
0890: 29 7b 0a 20 20 20 20 70 72 6f 6d 70 74 5f 66 6f  ){.    prompt_fo
08a0: 72 5f 70 61 73 73 70 68 72 61 73 65 28 7a 50 72  r_passphrase(zPr
08b0: 6f 6d 70 74 2c 20 70 50 61 73 73 70 68 72 61 73  ompt, pPassphras
08c0: 65 29 3b 0a 20 20 20 20 69 66 28 20 76 65 72 69  e);.    if( veri
08d0: 66 79 3d 3d 30 20 29 20 62 72 65 61 6b 3b 0a 20  fy==0 ) break;. 
08e0: 20 20 20 69 66 28 20 76 65 72 69 66 79 3d 3d 31     if( verify==1
08f0: 20 26 26 20 62 6c 6f 62 5f 73 69 7a 65 28 70 50   && blob_size(pP
0900: 61 73 73 70 68 72 61 73 65 29 3d 3d 30 20 29 20  assphrase)==0 ) 
0910: 62 72 65 61 6b 3b 0a 20 20 20 20 70 72 6f 6d 70  break;.    promp
0920: 74 5f 66 6f 72 5f 70 61 73 73 70 68 72 61 73 65  t_for_passphrase
0930: 28 22 41 67 61 69 6e 3a 20 22 2c 20 26 73 65 63  ("Again: ", &sec
0940: 6f 6e 64 54 72 79 29 3b 0a 20 20 20 20 69 66 28  ondTry);.    if(
0950: 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 70 50   blob_compare(pP
0960: 61 73 73 70 68 72 61 73 65 2c 20 26 73 65 63 6f  assphrase, &seco
0970: 6e 64 54 72 79 29 20 29 7b 0a 20 20 20 20 20 20  ndTry) ){.      
0980: 70 72 69 6e 74 66 28 22 50 61 73 73 70 68 72 61  printf("Passphra
0990: 73 65 73 20 64 6f 20 6e 6f 74 20 6d 61 74 63 68  ses do not match
09a0: 2e 20 20 54 72 79 20 61 67 61 69 6e 2e 2e 2e 5c  .  Try again...\
09b0: 6e 22 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a  n");.    }else{.
09c0: 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20        break;.   
09d0: 20 7d 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 72 65   }.  }.  blob_re
09e0: 73 65 74 28 26 73 65 63 6f 6e 64 54 72 79 29 3b  set(&secondTry);
09f0: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72 6f 6d 70 74  .}../*.** Prompt
0a00: 20 74 68 65 20 75 73 65 72 20 74 6f 20 65 6e 74   the user to ent
0a10: 65 72 20 61 20 73 69 6e 67 6c 65 20 6c 69 6e 65  er a single line
0a20: 20 6f 66 20 74 65 78 74 2e 0a 2a 2f 0a 73 74 61   of text..*/.sta
0a30: 74 69 63 20 76 6f 69 64 20 70 72 6f 6d 70 74 5f  tic void prompt_
0a40: 75 73 65 72 28 63 6f 6e 73 74 20 63 68 61 72 20  user(const char 
0a50: 2a 7a 50 72 6f 6d 70 74 2c 20 42 6c 6f 62 20 2a  *zPrompt, Blob *
0a60: 70 49 6e 29 7b 0a 20 20 63 68 61 72 20 2a 7a 3b  pIn){.  char *z;
0a70: 0a 20 20 63 68 61 72 20 7a 4c 69 6e 65 5b 31 30  .  char zLine[10
0a80: 30 30 5d 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f  00];.  blob_zero
0a90: 28 70 49 6e 29 3b 0a 20 20 70 72 69 6e 74 66 28  (pIn);.  printf(
0aa0: 22 25 73 22 2c 20 7a 50 72 6f 6d 70 74 29 3b 0a  "%s", zPrompt);.
0ab0: 20 20 66 66 6c 75 73 68 28 73 74 64 6f 75 74 29    fflush(stdout)
0ac0: 3b 0a 20 20 7a 20 3d 20 66 67 65 74 73 28 7a 4c  ;.  z = fgets(zL
0ad0: 69 6e 65 2c 20 73 69 7a 65 6f 66 28 7a 4c 69 6e  ine, sizeof(zLin
0ae0: 65 29 2c 20 73 74 64 69 6e 29 3b 0a 20 20 69 66  e), stdin);.  if
0af0: 28 20 7a 20 29 7b 0a 20 20 20 20 73 74 72 69 70  ( z ){.    strip
0b00: 5f 73 74 72 69 6e 67 28 70 49 6e 2c 20 7a 29 3b  _string(pIn, z);
0b10: 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 43  .  }.}.../*.** C
0b20: 4f 4d 4d 41 4e 44 3a 20 20 75 73 65 72 0a 2a 2a  OMMAND:  user.**
0b30: 0a 2a 2a 20 44 69 73 70 61 74 63 68 65 72 20 66  .** Dispatcher f
0b40: 6f 72 20 76 61 72 69 6f 75 73 20 75 73 65 72 20  or various user 
0b50: 73 75 62 63 6f 6d 6d 61 6e 64 73 2e 0a 2a 2f 0a  subcommands..*/.
0b60: 76 6f 69 64 20 75 73 65 72 5f 63 6d 64 28 76 6f  void user_cmd(vo
0b70: 69 64 29 7b 0a 20 20 69 6e 74 20 6e 3b 0a 20 20  id){.  int n;.  
0b80: 64 62 5f 66 69 6e 64 5f 61 6e 64 5f 6f 70 65 6e  db_find_and_open
0b90: 5f 72 65 70 6f 73 69 74 6f 72 79 28 29 3b 0a 20  _repository();. 
0ba0: 20 69 66 28 20 67 2e 61 72 67 63 3c 33 20 29 7b   if( g.argc<3 ){
0bb0: 0a 20 20 20 20 75 73 61 67 65 28 22 63 61 70 61  .    usage("capa
0bc0: 62 69 6c 69 74 69 65 73 7c 64 65 66 61 75 6c 74  bilities|default
0bd0: 7c 6c 69 73 74 7c 6e 65 77 7c 70 61 73 73 77 6f  |list|new|passwo
0be0: 72 64 20 2e 2e 2e 22 29 3b 0a 20 20 7d 0a 20 20  rd ...");.  }.  
0bf0: 6e 20 3d 20 73 74 72 6c 65 6e 28 67 2e 61 72 67  n = strlen(g.arg
0c00: 76 5b 32 5d 29 3b 0a 20 20 69 66 28 20 6e 3e 3d  v[2]);.  if( n>=
0c10: 32 20 26 26 20 73 74 72 6e 63 6d 70 28 67 2e 61  2 && strncmp(g.a
0c20: 72 67 76 5b 32 5d 2c 22 6e 65 77 22 2c 6e 29 3d  rgv[2],"new",n)=
0c30: 3d 30 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 70  =0 ){.    Blob p
0c40: 61 73 73 77 64 2c 20 6c 6f 67 69 6e 2c 20 63 6f  asswd, login, co
0c50: 6e 74 61 63 74 3b 0a 0a 20 20 20 20 70 72 6f 6d  ntact;..    prom
0c60: 70 74 5f 75 73 65 72 28 22 6c 6f 67 69 6e 3a 20  pt_user("login: 
0c70: 22 2c 20 26 6c 6f 67 69 6e 29 3b 0a 20 20 20 20  ", &login);.    
0c80: 70 72 6f 6d 70 74 5f 75 73 65 72 28 22 63 6f 6e  prompt_user("con
0c90: 74 61 63 74 2d 69 6e 66 6f 3a 20 22 2c 20 26 63  tact-info: ", &c
0ca0: 6f 6e 74 61 63 74 29 3b 0a 20 20 20 20 70 72 6f  ontact);.    pro
0cb0: 6d 70 74 5f 66 6f 72 5f 70 61 73 73 77 6f 72 64  mpt_for_password
0cc0: 28 22 70 61 73 73 77 6f 72 64 3a 20 22 2c 20 26  ("password: ", &
0cd0: 70 61 73 73 77 64 2c 20 31 29 3b 0a 20 20 20 20  passwd, 1);.    
0ce0: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20  db_multi_exec(. 
0cf0: 20 20 20 20 20 22 49 4e 53 45 52 54 20 49 4e 54       "INSERT INT
0d00: 4f 20 75 73 65 72 28 6c 6f 67 69 6e 2c 70 77 2c  O user(login,pw,
0d10: 63 61 70 2c 69 6e 66 6f 29 22 0a 20 20 20 20 20  cap,info)".     
0d20: 20 22 56 41 4c 55 45 53 28 25 42 2c 25 42 2c 27   "VALUES(%B,%B,'
0d30: 6a 6e 6f 72 27 2c 25 42 29 22 2c 0a 20 20 20 20  jnor',%B)",.    
0d40: 20 20 26 6c 6f 67 69 6e 2c 20 26 70 61 73 73 77    &login, &passw
0d50: 64 2c 20 26 63 6f 6e 74 61 63 74 0a 20 20 20 20  d, &contact.    
0d60: 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 6e  );.  }else if( n
0d70: 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d 70 28 67  >=2 && strncmp(g
0d80: 2e 61 72 67 76 5b 32 5d 2c 22 64 65 66 61 75 6c  .argv[2],"defaul
0d90: 74 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20  t",n)==0 ){.    
0da0: 75 73 65 72 5f 73 65 6c 65 63 74 28 29 3b 0a 20  user_select();. 
0db0: 20 20 20 69 66 28 20 67 2e 61 72 67 63 3d 3d 33     if( g.argc==3
0dc0: 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66   ){.      printf
0dd0: 28 22 25 73 5c 6e 22 2c 20 67 2e 7a 4c 6f 67 69  ("%s\n", g.zLogi
0de0: 6e 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66  n);.    }else if
0df0: 28 20 67 2e 6c 6f 63 61 6c 4f 70 65 6e 20 29 7b  ( g.localOpen ){
0e00: 0a 20 20 20 20 20 20 64 62 5f 6c 73 65 74 28 22  .      db_lset("
0e10: 64 65 66 61 75 6c 74 2d 75 73 65 72 22 2c 20 67  default-user", g
0e20: 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20 20 20 7d 65  .zLogin);.    }e
0e30: 6c 73 65 7b 0a 20 20 20 20 20 20 64 62 5f 73 65  lse{.      db_se
0e40: 74 28 22 64 65 66 61 75 6c 74 2d 75 73 65 72 22  t("default-user"
0e50: 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20 20  , g.zLogin);.   
0e60: 20 7d 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 6e   }.  }else if( n
0e70: 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d 70 28 67  >=2 && strncmp(g
0e80: 2e 61 72 67 76 5b 32 5d 2c 22 6c 69 73 74 22 2c  .argv[2],"list",
0e90: 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20 53 74 6d  n)==0 ){.    Stm
0ea0: 74 20 71 3b 0a 20 20 20 20 64 62 5f 70 72 65 70  t q;.    db_prep
0eb0: 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43 54 20  are(&q, "SELECT 
0ec0: 6c 6f 67 69 6e 2c 20 69 6e 66 6f 20 46 52 4f 4d  login, info FROM
0ed0: 20 75 73 65 72 20 4f 52 44 45 52 20 42 59 20 6c   user ORDER BY l
0ee0: 6f 67 69 6e 22 29 3b 0a 20 20 20 20 77 68 69 6c  ogin");.    whil
0ef0: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d  e( db_step(&q)==
0f00: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20  SQLITE_ROW ){.  
0f10: 20 20 20 20 70 72 69 6e 74 66 28 22 25 2d 31 32      printf("%-12
0f20: 73 20 25 73 5c 6e 22 2c 20 64 62 5f 63 6f 6c 75  s %s\n", db_colu
0f30: 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 2c 20  mn_text(&q, 0), 
0f40: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26  db_column_text(&
0f50: 71 2c 20 31 29 29 3b 0a 20 20 20 20 7d 0a 20 20  q, 1));.    }.  
0f60: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71    db_finalize(&q
0f70: 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 6e  );.  }else if( n
0f80: 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d 70 28 67  >=2 && strncmp(g
0f90: 2e 61 72 67 76 5b 32 5d 2c 22 70 61 73 73 77 6f  .argv[2],"passwo
0fa0: 72 64 22 2c 32 29 3d 3d 30 20 29 7b 0a 20 20 20  rd",2)==0 ){.   
0fb0: 20 63 68 61 72 20 2a 7a 50 72 6f 6d 70 74 3b 0a   char *zPrompt;.
0fc0: 20 20 20 20 69 6e 74 20 75 69 64 3b 0a 20 20 20      int uid;.   
0fd0: 20 42 6c 6f 62 20 70 77 3b 0a 20 20 20 20 69 66   Blob pw;.    if
0fe0: 28 20 67 2e 61 72 67 63 21 3d 34 20 29 20 75 73  ( g.argc!=4 ) us
0ff0: 61 67 65 28 22 75 73 65 72 20 70 61 73 73 77 6f  age("user passwo
1000: 72 64 20 55 53 45 52 4e 41 4d 45 22 29 3b 0a 20  rd USERNAME");. 
1010: 20 20 20 75 69 64 20 3d 20 64 62 5f 69 6e 74 28     uid = db_int(
1020: 30 2c 20 22 53 45 4c 45 43 54 20 75 69 64 20 46  0, "SELECT uid F
1030: 52 4f 4d 20 75 73 65 72 20 57 48 45 52 45 20 6c  ROM user WHERE l
1040: 6f 67 69 6e 3d 25 51 22 2c 20 67 2e 61 72 67 76  ogin=%Q", g.argv
1050: 5b 33 5d 29 3b 0a 20 20 20 20 69 66 28 20 75 69  [3]);.    if( ui
1060: 64 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 66 6f  d==0 ){.      fo
1070: 73 73 69 6c 5f 66 61 74 61 6c 28 22 6e 6f 20 73  ssil_fatal("no s
1080: 75 63 68 20 75 73 65 72 3a 20 25 73 22 2c 20 67  uch user: %s", g
1090: 2e 61 72 67 76 5b 33 5d 29 3b 0a 20 20 20 20 7d  .argv[3]);.    }
10a0: 0a 20 20 20 20 7a 50 72 6f 6d 70 74 20 3d 20 6d  .    zPrompt = m
10b0: 70 72 69 6e 74 66 28 22 6e 65 77 20 70 61 73 73  printf("new pass
10c0: 77 64 20 66 6f 72 20 25 73 3a 20 22 2c 20 67 2e  wd for %s: ", g.
10d0: 61 72 67 76 5b 33 5d 29 3b 0a 20 20 20 20 70 72  argv[3]);.    pr
10e0: 6f 6d 70 74 5f 66 6f 72 5f 70 61 73 73 77 6f 72  ompt_for_passwor
10f0: 64 28 7a 50 72 6f 6d 70 74 2c 20 26 70 77 2c 20  d(zPrompt, &pw, 
1100: 31 29 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62  1);.    if( blob
1110: 5f 73 69 7a 65 28 26 70 77 29 3d 3d 30 20 29 7b  _size(&pw)==0 ){
1120: 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 70  .      printf("p
1130: 61 73 73 77 6f 72 64 20 75 6e 63 68 61 6e 67 65  assword unchange
1140: 64 5c 6e 22 29 3b 0a 20 20 20 20 7d 65 6c 73 65  d\n");.    }else
1150: 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69  {.      db_multi
1160: 5f 65 78 65 63 28 22 55 50 44 41 54 45 20 75 73  _exec("UPDATE us
1170: 65 72 20 53 45 54 20 70 77 3d 25 42 20 57 48 45  er SET pw=%B WHE
1180: 52 45 20 75 69 64 3d 25 64 22 2c 20 26 70 77 2c  RE uid=%d", &pw,
1190: 20 75 69 64 29 3b 0a 20 20 20 20 7d 0a 20 20 7d   uid);.    }.  }
11a0: 65 6c 73 65 20 69 66 28 20 6e 3e 3d 32 20 26 26  else if( n>=2 &&
11b0: 20 73 74 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b   strncmp(g.argv[
11c0: 32 5d 2c 22 63 61 70 61 62 69 6c 69 74 69 65 73  2],"capabilities
11d0: 22 2c 32 29 3d 3d 30 20 29 7b 0a 20 20 20 20 69  ",2)==0 ){.    i
11e0: 6e 74 20 75 69 64 3b 0a 20 20 20 20 69 66 28 20  nt uid;.    if( 
11f0: 67 2e 61 72 67 63 21 3d 34 20 26 26 20 67 2e 61  g.argc!=4 && g.a
1200: 72 67 63 21 3d 35 20 29 7b 0a 20 20 20 20 20 20  rgc!=5 ){.      
1210: 75 73 61 67 65 28 22 75 73 65 72 20 63 61 70 61  usage("user capa
1220: 62 69 6c 69 74 69 65 73 20 55 53 45 52 4e 41 4d  bilities USERNAM
1230: 45 20 3f 50 45 52 4d 49 53 53 49 4f 4e 53 3f 22  E ?PERMISSIONS?"
1240: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 75 69 64  );.    }.    uid
1250: 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45   = db_int(0, "SE
1260: 4c 45 43 54 20 75 69 64 20 46 52 4f 4d 20 75 73  LECT uid FROM us
1270: 65 72 20 57 48 45 52 45 20 6c 6f 67 69 6e 3d 25  er WHERE login=%
1280: 51 22 2c 20 67 2e 61 72 67 76 5b 33 5d 29 3b 0a  Q", g.argv[3]);.
1290: 20 20 20 20 69 66 28 20 75 69 64 3d 3d 30 20 29      if( uid==0 )
12a0: 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66  {.      fossil_f
12b0: 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 75 73  atal("no such us
12c0: 65 72 3a 20 25 73 22 2c 20 67 2e 61 72 67 76 5b  er: %s", g.argv[
12d0: 33 5d 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69  3]);.    }.    i
12e0: 66 28 20 67 2e 61 72 67 63 3d 3d 35 20 29 7b 0a  f( g.argc==5 ){.
12f0: 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65        db_multi_e
1300: 78 65 63 28 0a 20 20 20 20 20 20 20 20 22 55 50  xec(.        "UP
1310: 44 41 54 45 20 75 73 65 72 20 53 45 54 20 63 61  DATE user SET ca
1320: 70 3d 25 51 20 57 48 45 52 45 20 75 69 64 3d 25  p=%Q WHERE uid=%
1330: 64 22 2c 20 67 2e 61 72 67 76 5b 34 5d 2c 0a 20  d", g.argv[4],. 
1340: 20 20 20 20 20 20 20 75 69 64 0a 20 20 20 20 20         uid.     
1350: 20 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 70 72   );.    }.    pr
1360: 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 64 62 5f  intf("%s\n", db_
1370: 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20  text(0, "SELECT 
1380: 63 61 70 20 46 52 4f 4d 20 75 73 65 72 20 57 48  cap FROM user WH
1390: 45 52 45 20 75 69 64 3d 25 64 22 2c 20 75 69 64  ERE uid=%d", uid
13a0: 29 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  ));.  }else{.   
13b0: 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 75   fossil_panic("u
13c0: 73 65 72 20 73 75 62 63 6f 6d 6d 61 6e 64 20 73  ser subcommand s
13d0: 68 6f 75 6c 64 20 62 65 20 6f 6e 65 20 6f 66 3a  hould be one of:
13e0: 20 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20   ".             
13f0: 20 20 20 20 22 63 61 70 61 62 69 6c 69 74 69 65      "capabilitie
1400: 73 20 64 65 66 61 75 6c 74 20 6c 69 73 74 20 6e  s default list n
1410: 65 77 20 70 61 73 73 77 6f 72 64 22 29 3b 0a 20  ew password");. 
1420: 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 41 74 74 65   }.}../*.** Atte
1430: 6d 70 74 20 74 6f 20 73 65 74 20 74 68 65 20 75  mpt to set the u
1440: 73 65 72 20 74 6f 20 7a 4c 6f 67 69 6e 0a 2a 2f  ser to zLogin.*/
1450: 0a 73 74 61 74 69 63 20 69 6e 74 20 61 74 74 65  .static int atte
1460: 6d 70 74 5f 75 73 65 72 28 63 6f 6e 73 74 20 63  mpt_user(const c
1470: 68 61 72 20 2a 7a 4c 6f 67 69 6e 29 7b 0a 20 20  har *zLogin){.  
1480: 69 6e 74 20 75 69 64 3b 0a 0a 20 20 69 66 28 20  int uid;..  if( 
1490: 7a 4c 6f 67 69 6e 3d 3d 30 20 29 7b 0a 20 20 20  zLogin==0 ){.   
14a0: 20 72 65 74 75 72 6e 20 30 3b 0a 20 20 7d 0a 20   return 0;.  }. 
14b0: 20 75 69 64 20 3d 20 64 62 5f 69 6e 74 28 30 2c   uid = db_int(0,
14c0: 20 22 53 45 4c 45 43 54 20 75 69 64 20 46 52 4f   "SELECT uid FRO
14d0: 4d 20 75 73 65 72 20 57 48 45 52 45 20 6c 6f 67  M user WHERE log
14e0: 69 6e 3d 25 51 22 2c 20 7a 4c 6f 67 69 6e 29 3b  in=%Q", zLogin);
14f0: 0a 20 20 69 66 28 20 75 69 64 20 29 7b 0a 20 20  .  if( uid ){.  
1500: 20 20 67 2e 75 73 65 72 55 69 64 20 3d 20 75 69    g.userUid = ui
1510: 64 3b 0a 20 20 20 20 67 2e 7a 4c 6f 67 69 6e 20  d;.    g.zLogin 
1520: 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20  = mprintf("%s", 
1530: 7a 4c 6f 67 69 6e 29 3b 0a 20 20 20 20 72 65 74  zLogin);.    ret
1540: 75 72 6e 20 31 3b 0a 20 20 7d 0a 20 20 72 65 74  urn 1;.  }.  ret
1550: 75 72 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  urn 0;.}../*.** 
1560: 46 69 67 75 72 65 20 6f 75 74 20 77 68 61 74 20  Figure out what 
1570: 75 73 65 72 20 69 73 20 61 74 20 74 68 65 20 63  user is at the c
1580: 6f 6e 74 72 6f 6c 73 2e 0a 2a 2a 0a 2a 2a 20 20  ontrols..**.**  
1590: 20 28 31 29 20 20 55 73 65 20 74 68 65 20 2d 2d   (1)  Use the --
15a0: 75 73 65 72 20 61 6e 64 20 2d 55 20 63 6f 6d 6d  user and -U comm
15b0: 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e 73  and-line options
15c0: 2e 0a 2a 2a 0a 2a 2a 20 20 20 28 32 29 20 20 49  ..**.**   (2)  I
15d0: 66 20 74 68 65 20 6c 6f 63 61 6c 20 64 61 74 61  f the local data
15e0: 62 61 73 65 20 69 73 20 6f 70 65 6e 2c 20 63 68  base is open, ch
15f0: 65 63 6b 20 69 6e 20 56 56 41 52 2e 0a 2a 2a 0a  eck in VVAR..**.
1600: 2a 2a 20 20 20 28 33 29 20 20 43 68 65 63 6b 20  **   (3)  Check 
1610: 74 68 65 20 64 65 66 61 75 6c 74 20 75 73 65 72  the default user
1620: 20 69 6e 20 74 68 65 20 72 65 70 6f 73 69 74 6f   in the reposito
1630: 72 79 0a 2a 2a 0a 2a 2a 20 20 20 28 34 29 20 20  ry.**.**   (4)  
1640: 54 72 79 20 74 68 65 20 55 53 45 52 20 65 6e 76  Try the USER env
1650: 69 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c  ironment variabl
1660: 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 28 35 29 20 20  e..**.**   (5)  
1670: 55 73 65 20 74 68 65 20 66 69 72 73 74 20 75 73  Use the first us
1680: 65 72 20 69 6e 20 74 68 65 20 55 53 45 52 20 74  er in the USER t
1690: 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20  able..**.** The 
16a0: 75 73 65 72 20 6e 61 6d 65 20 69 73 20 73 74 6f  user name is sto
16b0: 72 65 64 20 69 6e 20 67 2e 7a 4c 6f 67 69 6e 2e  red in g.zLogin.
16c0: 20 20 54 68 65 20 75 69 64 20 69 73 20 69 6e 20    The uid is in 
16d0: 67 2e 75 73 65 72 55 69 64 2e 0a 2a 2f 0a 76 6f  g.userUid..*/.vo
16e0: 69 64 20 75 73 65 72 5f 73 65 6c 65 63 74 28 76  id user_select(v
16f0: 6f 69 64 29 7b 0a 20 20 53 74 6d 74 20 73 3b 0a  oid){.  Stmt s;.
1700: 0a 20 20 69 66 28 20 67 2e 75 73 65 72 55 69 64  .  if( g.userUid
1710: 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 69 66 28   ) return;.  if(
1720: 20 61 74 74 65 6d 70 74 5f 75 73 65 72 28 67 2e   attempt_user(g.
1730: 7a 4c 6f 67 69 6e 29 20 29 20 72 65 74 75 72 6e  zLogin) ) return
1740: 3b 0a 0a 20 20 69 66 28 20 67 2e 6c 6f 63 61 6c  ;..  if( g.local
1750: 4f 70 65 6e 20 26 26 20 61 74 74 65 6d 70 74 5f  Open && attempt_
1760: 75 73 65 72 28 64 62 5f 6c 67 65 74 28 22 64 65  user(db_lget("de
1770: 66 61 75 6c 74 2d 75 73 65 72 22 2c 30 29 29 20  fault-user",0)) 
1780: 29 20 72 65 74 75 72 6e 3b 0a 0a 20 20 69 66 28  ) return;..  if(
1790: 20 61 74 74 65 6d 70 74 5f 75 73 65 72 28 64 62   attempt_user(db
17a0: 5f 67 65 74 28 22 64 65 66 61 75 6c 74 2d 75 73  _get("default-us
17b0: 65 72 22 2c 20 30 29 29 20 29 20 72 65 74 75 72  er", 0)) ) retur
17c0: 6e 3b 0a 0a 20 20 69 66 28 20 61 74 74 65 6d 70  n;..  if( attemp
17d0: 74 5f 75 73 65 72 28 67 65 74 65 6e 76 28 22 55  t_user(getenv("U
17e0: 53 45 52 22 29 29 20 29 20 72 65 74 75 72 6e 3b  SER")) ) return;
17f0: 0a 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26  ..  db_prepare(&
1800: 73 2c 20 22 53 45 4c 45 43 54 20 75 69 64 2c 20  s, "SELECT uid, 
1810: 6c 6f 67 69 6e 20 46 52 4f 4d 20 75 73 65 72 20  login FROM user 
1820: 57 48 45 52 45 20 6c 6f 67 69 6e 3c 3e 27 61 6e  WHERE login<>'an
1830: 6f 6e 79 6d 6f 75 73 27 22 29 3b 0a 20 20 69 66  onymous'");.  if
1840: 28 20 64 62 5f 73 74 65 70 28 26 73 29 3d 3d 53  ( db_step(&s)==S
1850: 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20  QLITE_ROW ){.   
1860: 20 67 2e 75 73 65 72 55 69 64 20 3d 20 64 62 5f   g.userUid = db_
1870: 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 73 2c 20 30  column_int(&s, 0
1880: 29 3b 0a 20 20 20 20 67 2e 7a 4c 6f 67 69 6e 20  );.    g.zLogin 
1890: 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20  = mprintf("%s", 
18a0: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26  db_column_text(&
18b0: 73 2c 20 31 29 29 3b 0a 20 20 7d 0a 20 20 64 62  s, 1));.  }.  db
18c0: 5f 66 69 6e 61 6c 69 7a 65 28 26 73 29 3b 0a 0a  _finalize(&s);..
18d0: 20 20 69 66 28 20 67 2e 75 73 65 72 55 69 64 3d    if( g.userUid=
18e0: 3d 30 20 29 7b 0a 20 20 20 20 64 62 5f 70 72 65  =0 ){.    db_pre
18f0: 70 61 72 65 28 26 73 2c 20 22 53 45 4c 45 43 54  pare(&s, "SELECT
1900: 20 75 69 64 2c 20 6c 6f 67 69 6e 20 46 52 4f 4d   uid, login FROM
1910: 20 75 73 65 72 22 29 3b 0a 20 20 20 20 69 66 28   user");.    if(
1920: 20 64 62 5f 73 74 65 70 28 26 73 29 3d 3d 53 51   db_step(&s)==SQ
1930: 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20  LITE_ROW ){.    
1940: 20 20 67 2e 75 73 65 72 55 69 64 20 3d 20 64 62    g.userUid = db
1950: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 73 2c 20  _column_int(&s, 
1960: 30 29 3b 0a 20 20 20 20 20 20 67 2e 7a 4c 6f 67  0);.      g.zLog
1970: 69 6e 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73  in = mprintf("%s
1980: 22 2c 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78  ", db_column_tex
1990: 74 28 26 73 2c 20 31 29 29 3b 0a 20 20 20 20 7d  t(&s, 1));.    }
19a0: 0a 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65  .    db_finalize
19b0: 28 26 73 29 3b 0a 20 20 7d 0a 0a 20 20 69 66 28  (&s);.  }..  if(
19c0: 20 67 2e 75 73 65 72 55 69 64 3d 3d 30 20 29 7b   g.userUid==0 ){
19d0: 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78  .    db_multi_ex
19e0: 65 63 28 0a 20 20 20 20 20 20 22 49 4e 53 45 52  ec(.      "INSER
19f0: 54 20 49 4e 54 4f 20 75 73 65 72 28 6c 6f 67 69  T INTO user(logi
1a00: 6e 2c 20 70 77 2c 20 63 61 70 2c 20 69 6e 66 6f  n, pw, cap, info
1a10: 29 22 0a 20 20 20 20 20 20 22 56 41 4c 55 45 53  )".      "VALUES
1a20: 28 27 61 6e 6f 6e 79 6d 6f 75 73 27 2c 20 27 27  ('anonymous', ''
1a30: 2c 20 27 27 2c 20 27 27 29 22 0a 20 20 20 20 29  , '', '')".    )
1a40: 3b 0a 20 20 20 20 67 2e 75 73 65 72 55 69 64 20  ;.    g.userUid 
1a50: 3d 20 64 62 5f 6c 61 73 74 5f 69 6e 73 65 72 74  = db_last_insert
1a60: 5f 72 6f 77 69 64 28 29 3b 0a 20 20 20 20 67 2e  _rowid();.    g.
1a70: 7a 4c 6f 67 69 6e 20 3d 20 22 61 6e 6f 6e 79 6d  zLogin = "anonym
1a80: 6f 75 73 22 3b 0a 20 20 7d 0a 7d 0a              ous";.  }.}.