Project

General

Profile

Actions

Bug #2063

open

Database will always try to create a new user on log in

Added by Zoé Scarlett Jaekel 14 days ago. Updated 12 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
07/01/2026
Due date:
% Done:

0%

Estimated time:

Description

Description

A freeciv-server started with authentification configured, see `auth.conf` and the corresponding pre-filled password database: `user_auth.sqlite` that was created during a previous run with `--Newusers` will always try to create a new user and not allow logins already present.

Reproduction

  1. Start freeciv-server version 3.2.4
    freeciv-server -m --auth --Database auth.conf --Newusers
    
  2. Connect with a client
    I used the gtk client (gtk 3.22).
    Log in with `user` and password `password`, confirm the password.
    Then disconnect again.
  3. Connect with the client (again)
    (again, gtk client)
    Use the same credentials and observe the failure in the server logs:
    1: lua error:
        /etc/freeciv/database.lua:281: LuaSQL: UNIQUE constraint failed: fcdb_auth.name
    stack traceback:
        : in function 'assert'
        /etc/freeciv/database.lua:281: in function 'user_save'
    1: Error writing to database for: user
    
    

Comments

It seems to me that user recognition is broken, because when the server is run with registrations closed, it won't even let me enter any password for the pre-registered user and reject the connection.

Versions

I can reproduce this on 3.2.4 no flakiness.

Version 3.2.2 works as expected.


Files

auth.conf (54 Bytes) auth.conf Zoé Scarlett Jaekel, 07/01/2026 03:04 PM
2026-07-02 11-40-48.mp4 (2.79 MB) 2026-07-02 11-40-48.mp4 The registration is issued twice, and the lua crashes. Zoé Scarlett Jaekel, 07/02/2026 12:52 PM
freeciv.log (374 KB) freeciv.log Zoé Scarlett Jaekel, 07/02/2026 01:01 PM
UserExistsLog.patch (362 Bytes) UserExistsLog.patch Marko Lindqvist, 07/02/2026 04:30 PM
BoolReturnLog.patch (721 Bytes) BoolReturnLog.patch Marko Lindqvist, 07/03/2026 12:46 PM
Actions #1

Updated by Zoé Scarlett Jaekel 14 days ago

I suspect this to be an issue with the lua script call. I cannot work around this in database.lua in any way.

Actions #2

Updated by Marko Lindqvist 14 days ago

I can't reproduce this.

There's also no obviously related changes between 3.2.2 and 3.2.4.

Do the contents of the database look sane after first login (to create the account)?
$ sqlite3 user_auth.sqlite
SQLite version 3.46.1 2024-08-13 09:16:08
Enter ".help" for usage hints.
sqlite> select * from fcdb_auth;
1|cazfi|e7e941b1f09f266540c6780db51d5f58||1782983871|1782983871|::1|::1|1

Actions #3

Updated by Zoé Scarlett Jaekel 14 days ago

Do the contents of the database look sane after first login (to create the account)?

Yes, they look very similar for me:

1|vego|e10adc3949ba59abbe56e057f20f883e||1782984826|1782984826|::1|::1|1

Actions #4

Updated by Zoé Scarlett Jaekel 14 days ago

I can't reproduce this.

I have reinstalled freeciv-common.aarch64 (fedora 44) on my server and can still reproduce the issue, I have attached a video of the bug reproduction.

I can not do this locally, e.g. on x86_64 on my laptop with a local server via localhost.

Actions #5

Updated by Zoé Scarlett Jaekel 14 days ago

I have reinstalled freeciv-common.aarch64 (fedora 44) on my server and can still reproduce the issue, I have attached a video of the bug reproduction.

I have recorded a log with -v d, in case you get any use of it.

Actions #6

Updated by Marko Lindqvist 13 days ago

Attached is a patch to add some logging to database.lua. Can you test with it, so we would learn whether the error happens already within database.lua user_exists(), or is it later in the server binary?

Actions #7

Updated by Zoé Scarlett Jaekel 13 days ago

Marko Lindqvist wrote in #note-6:

Attached is a patch to add some logging to database.lua. Can you test with it, so we would learn whether the error happens already within database.lua user_exists(), or is it later in the server binary?

I have applied the patch to my installation for the file at /etc/freeciv/database.lua.

Then, doing the registration and re-login procedure gave the following output on stdout:

3: Connection request from vego from X.
3: c1 has client version 3.2.4
3: User does not exist
>
3: vego has connected from X.
>
3: Lost connection: vego from X (client disconnected) (player Vego).
3: Removing player Vego.
3: AI*1 has been added as Easy level AI-controlled player (classic).
>
3: Connection request from vego from X
3: c2 has client version 3.2.4
3: User exists
>
1: lua error:
    /etc/freeciv/database.lua:287: LuaSQL: UNIQUE constraint failed: fcdb_auth.name
stack traceback:
    : in function 'assert'
    /etc/freeciv/database.lua:287: in function 'user_save'
1: Error writing to database for: vego

I did a little searching in the codebase yesterday to figure out whether it was something I could quickly hack around and came to the conclusion that the lua return value is not properly written back to the C code.

Now I have also never worked with this, but I feel like the `bool exists` (which is passed by reference to lua via va_args) is not the size the lua code expects it to be.

Please take my considerations with a grain of salt, it's a new codebase for me and I didn't get around to testing any of them.

Actions #8

Updated by Marko Lindqvist 13 days ago

Another logging patch (with one cast added), this time for the C-code side.

Actions #9

Updated by Marko Lindqvist 12 days ago

Could also be related to this:

man va_arg

...
If ap is passed to a function that uses va_arg(ap,type), then the value of ap is undefined after the return of
that function.
...

We first pass ap to a function to extract lua call arguments. Later we pass it to another function extracting return values, assuming it's still in the state that we left it in the first function.

Actions #10

Updated by Zoé Scarlett Jaekel 12 days ago

Marko Lindqvist wrote in #note-8:

Another logging patch (with one cast added), this time for the C-code side.

Thank you for the patch! I'll report back as soon as I get the cross build working or directly on my server.

Actions

Also available in: Atom PDF