Fossil SCM
If unable to determine the user by the normal techniques, don't guess. Print a helpful error message and quit. Otherwise strange user names end up in the log.
Commit
1e7262b724b666b4751768b0b70c52df2548610f
Parent
75bcb48089c3e37…
1 file changed
+8
-29
+8
-29
| --- src/user.c | ||
| +++ src/user.c | ||
| @@ -309,12 +309,10 @@ | ||
| 309 | 309 | ** (5) Use the first user in the USER table. |
| 310 | 310 | ** |
| 311 | 311 | ** The user name is stored in g.zLogin. The uid is in g.userUid. |
| 312 | 312 | */ |
| 313 | 313 | void user_select(void){ |
| 314 | - Stmt s; | |
| 315 | - | |
| 316 | 314 | if( g.userUid ) return; |
| 317 | 315 | if( g.zLogin ){ |
| 318 | 316 | if( attempt_user(g.zLogin)==0 ){ |
| 319 | 317 | fossil_fatal("no such user: %s", g.zLogin); |
| 320 | 318 | }else{ |
| @@ -326,37 +324,18 @@ | ||
| 326 | 324 | |
| 327 | 325 | if( attempt_user(db_get("default-user", 0)) ) return; |
| 328 | 326 | |
| 329 | 327 | if( attempt_user(fossil_getenv("USER")) ) return; |
| 330 | 328 | |
| 331 | - db_prepare(&s, | |
| 332 | - "SELECT uid, login FROM user" | |
| 333 | - " WHERE login NOT IN ('anonymous','nobody','reader','developer')" | |
| 334 | - ); | |
| 335 | - if( db_step(&s)==SQLITE_ROW ){ | |
| 336 | - g.userUid = db_column_int(&s, 0); | |
| 337 | - g.zLogin = mprintf("%s", db_column_text(&s, 1)); | |
| 338 | - } | |
| 339 | - db_finalize(&s); | |
| 340 | - | |
| 341 | - if( g.userUid==0 ){ | |
| 342 | - db_prepare(&s, "SELECT uid, login FROM user"); | |
| 343 | - if( db_step(&s)==SQLITE_ROW ){ | |
| 344 | - g.userUid = db_column_int(&s, 0); | |
| 345 | - g.zLogin = mprintf("%s", db_column_text(&s, 1)); | |
| 346 | - } | |
| 347 | - db_finalize(&s); | |
| 348 | - } | |
| 349 | - | |
| 350 | - if( g.userUid==0 ){ | |
| 351 | - db_multi_exec( | |
| 352 | - "INSERT INTO user(login, pw, cap, info, mtime)" | |
| 353 | - "VALUES('anonymous', '', 'cfghjkmnoqw', '', now())" | |
| 354 | - ); | |
| 355 | - g.userUid = db_last_insert_rowid(); | |
| 356 | - g.zLogin = "anonymous"; | |
| 357 | - } | |
| 329 | + if( attempt_user(fossil_getenv("USERNAME")) ) return; | |
| 330 | + | |
| 331 | + fossil_print( | |
| 332 | + "Cannot figure out who your are! Consider using the --user\n" | |
| 333 | + "command line option, or setting your USER environment variable\n" | |
| 334 | + "or setting a default user with \"fossil user default USER\".\n" | |
| 335 | + ); | |
| 336 | + fossil_fatal("cannot determine user"); | |
| 358 | 337 | } |
| 359 | 338 | |
| 360 | 339 | |
| 361 | 340 | /* |
| 362 | 341 | ** COMMAND: test-hash-passwords |
| 363 | 342 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -309,12 +309,10 @@ | |
| 309 | ** (5) Use the first user in the USER table. |
| 310 | ** |
| 311 | ** The user name is stored in g.zLogin. The uid is in g.userUid. |
| 312 | */ |
| 313 | void user_select(void){ |
| 314 | Stmt s; |
| 315 | |
| 316 | if( g.userUid ) return; |
| 317 | if( g.zLogin ){ |
| 318 | if( attempt_user(g.zLogin)==0 ){ |
| 319 | fossil_fatal("no such user: %s", g.zLogin); |
| 320 | }else{ |
| @@ -326,37 +324,18 @@ | |
| 326 | |
| 327 | if( attempt_user(db_get("default-user", 0)) ) return; |
| 328 | |
| 329 | if( attempt_user(fossil_getenv("USER")) ) return; |
| 330 | |
| 331 | db_prepare(&s, |
| 332 | "SELECT uid, login FROM user" |
| 333 | " WHERE login NOT IN ('anonymous','nobody','reader','developer')" |
| 334 | ); |
| 335 | if( db_step(&s)==SQLITE_ROW ){ |
| 336 | g.userUid = db_column_int(&s, 0); |
| 337 | g.zLogin = mprintf("%s", db_column_text(&s, 1)); |
| 338 | } |
| 339 | db_finalize(&s); |
| 340 | |
| 341 | if( g.userUid==0 ){ |
| 342 | db_prepare(&s, "SELECT uid, login FROM user"); |
| 343 | if( db_step(&s)==SQLITE_ROW ){ |
| 344 | g.userUid = db_column_int(&s, 0); |
| 345 | g.zLogin = mprintf("%s", db_column_text(&s, 1)); |
| 346 | } |
| 347 | db_finalize(&s); |
| 348 | } |
| 349 | |
| 350 | if( g.userUid==0 ){ |
| 351 | db_multi_exec( |
| 352 | "INSERT INTO user(login, pw, cap, info, mtime)" |
| 353 | "VALUES('anonymous', '', 'cfghjkmnoqw', '', now())" |
| 354 | ); |
| 355 | g.userUid = db_last_insert_rowid(); |
| 356 | g.zLogin = "anonymous"; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | |
| 361 | /* |
| 362 | ** COMMAND: test-hash-passwords |
| 363 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -309,12 +309,10 @@ | |
| 309 | ** (5) Use the first user in the USER table. |
| 310 | ** |
| 311 | ** The user name is stored in g.zLogin. The uid is in g.userUid. |
| 312 | */ |
| 313 | void user_select(void){ |
| 314 | if( g.userUid ) return; |
| 315 | if( g.zLogin ){ |
| 316 | if( attempt_user(g.zLogin)==0 ){ |
| 317 | fossil_fatal("no such user: %s", g.zLogin); |
| 318 | }else{ |
| @@ -326,37 +324,18 @@ | |
| 324 | |
| 325 | if( attempt_user(db_get("default-user", 0)) ) return; |
| 326 | |
| 327 | if( attempt_user(fossil_getenv("USER")) ) return; |
| 328 | |
| 329 | if( attempt_user(fossil_getenv("USERNAME")) ) return; |
| 330 | |
| 331 | fossil_print( |
| 332 | "Cannot figure out who your are! Consider using the --user\n" |
| 333 | "command line option, or setting your USER environment variable\n" |
| 334 | "or setting a default user with \"fossil user default USER\".\n" |
| 335 | ); |
| 336 | fossil_fatal("cannot determine user"); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | /* |
| 341 | ** COMMAND: test-hash-passwords |
| 342 |