/* ** Figure out what user is at the controls. ** ** (1) Use the --user and -U command-line options. ** ** (2) If the local database is open, check in VVAR. ** ** (3) Check the default user in the repository ** ** (4) Try the USER environment variable. ** ** (5) Use the first user in the USER table. ** ** The user name is stored in g.zLogin. The uid is in g.userUid. */ void user_select(void){ Stmt s; if( g.userUid ) return; if( attempt_user(g.zLogin) ) return; if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return; 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 NOT IN ('anonymous','nobody','reader','developer')" ); if( db_step(&s)==SQLITE_ROW ){ g.userUid = db_column_int(&s, 0); g.zLogin = mprintf("%s", db_column_text(&s, 1)); } db_finalize(&s); if( g.userUid==0 ){ db_prepare(&s, "SELECT uid, login FROM user"); if( db_step(&s)==SQLITE_ROW ){ g.userUid = db_column_int(&s, 0); g.zLogin = mprintf("%s", db_column_text(&s, 1)); } db_finalize(&s); } if( g.userUid==0 ){ db_multi_exec( "INSERT INTO user(login, pw, cap, info)" "VALUES('anonymous', '', 'cfghjkmnoqw', '')" ); g.userUid = db_last_insert_rowid(); g.zLogin = "******"; } }
/* ** Figure out what user is at the controls. ** ** (1) Use the --user and -U command-line options. ** ** (2) If the local database is open, check in VVAR. ** ** (3) Check the default user in the repository ** ** (4) Try the USER environment variable. ** ** (5) Try the USERNAME environment variable. ** ** (6) Check if the user can be extracted from the remote URL. ** ** The user name is stored in g.zLogin. The uid is in g.userUid. */ void user_select(void){ char *zUrl; if( g.userUid ) return; if( g.zLogin ){ if( attempt_user(g.zLogin)==0 ){ fossil_fatal("no such user: %s", g.zLogin); }else{ return; } } if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return; if( attempt_user(db_get("default-user", 0)) ) return; if( attempt_user(fossil_getenv("USER")) ) return; if( attempt_user(fossil_getenv("USERNAME")) ) return; zUrl = db_get("last-sync-url", 0); if( zUrl ){ url_parse(zUrl); if( attempt_user(g.urlUser) ) return; } fossil_print( "Cannot figure out who you are! Consider using the --user\n" "command line option, setting your USER environment variable,\n" "or setting a default user with \"fossil user default USER\".\n" ); fossil_fatal("cannot determine user"); }