Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle autologin auth attempt errors #1775

Merged
merged 5 commits into from
Aug 20, 2023

Conversation

SgAkErRu
Copy link
Contributor

@SgAkErRu SgAkErRu commented Jul 31, 2023

If the autologin auth attempt failed for any reason, then start socket server and greeter (launch sddm theme, like as if there was no autologin at all).

@Vogtinator
Copy link
Contributor

IMO this is the wrong place for such a check. If the auth attempt fails for any reason, it should be handled gracefully.

@SgAkErRu
Copy link
Contributor Author

SgAkErRu commented Jul 31, 2023

It is attempt to autologin, why we need to try to auth, if we know right away that it won't work? A little higher in this function, session is checked in a similar way.

It seems to me there is no point in making such an attempt. But anyway I see problem with handling auth attempt after autologin in that m_socketServer (which, as it seemed to me, is engaged in handling the failed authorization signal) is not even launched before autologin attempt (but I can be wrong).

Also, proposed patch is similar to this case (there we don't even try to log in if it doesn't make sense).

@SgAkErRu
Copy link
Contributor Author

SgAkErRu commented Jul 31, 2023

But I think I can trying to move that check into Display::startAuth, following the example of sanity session checks there.

What do you think about this idea?

@Vogtinator
Copy link
Contributor

It is attempt to autologin, why we need to try to auth, if we know right away that it won't work? A little higher in this function, session is checked in a similar way.

That's actually for a different reason: The session has to be found to set sessionType correctly.

It seems to me there is no point in making such an attempt. But anyway I see problem with handling auth attempt after autologin in that m_socketServer (which, as it seemed to me, is engaged in handling the failed authorization signal) is not even launched before autologin attempt (but I can be wrong).

If that's the case, that should probably be changed. IMO autologin should be as close to regular login as possible.

Also, proposed patch is similar to this case (there we don't even try to log in if it doesn't make sense).

Yeah, but that's also a case of doing an early check. Even if you remove this condition, it'll behave the same way. Login will just be refused by the PAM backend instead of the daemon.

But I think I can trying to move that check into Display::startAuth, following the example of sanity session checks there.

What do you think about this idea?

Not wrong, but IMO it's still important to handle autologin auth failures in any case, not just for wrong usernames.

@SgAkErRu SgAkErRu changed the title Check if the autologin user actually exists Handle autologin auth attempt errors Jul 31, 2023
@Vogtinator
Copy link
Contributor

The logic right now looks good, but what I don't really like is that there are now two ways autologin can fail: Synchronosly (returns false) and asynchronously (auth failure signal). Any idea how this could be unified? That avoids subtle errors like somehow ending up without m_auth->setAutologin(false); in some weird circumstance.

@SgAkErRu
Copy link
Contributor Author

SgAkErRu commented Aug 4, 2023

...two ways autologin can fail: Synchronosly (returns false) and asynchronously (auth failure signal). Any idea how this could be unified?

I think, still, they have a different nature: synchronous failure is a failure of early checks, and async failure is the authorization failure.

But, I think we can try to reduce the difference between them, if we put failure handling in a separate function (i mean that handling):

qWarning() << "Autologin failed!";
m_auth->setAutologin(false);
startSocketServerAndGreeter();

And will use that function in Display::slotAuthError and Display::attemptAutologin() directly, without returning boolean from Display::attemptAutologin() in Display::displayServerStarted(), so it will be just:

attemptAutologin();
return;

instead of

bool success = attemptAutologin();
if (success) {
    return;
} else {
    qWarning() << "Autologin failed!";
}

in Display::displayServerStarted() function.

@Vogtinator
Copy link
Contributor

...two ways autologin can fail: Synchronosly (returns false) and asynchronously (auth failure signal). Any idea how this could be unified?

I think, still, they have a different nature: synchronous failure is a failure of early checks, and async failure is the authorization failure.

IMO that's an "implementation detail" (as far as that is possible inside the same class). The result is the same. I'm thinking along the lines of emitting slotAuthError within attemptAutologin for instance, though that can be misleading in other ways.

But, I think we can try to reduce the difference between them, if we put failure handling in a separate function (i mean that handling):

qWarning() << "Autologin failed!";
m_auth->setAutologin(false);
startSocketServerAndGreeter();

And will use that function in Display::slotAuthError and Display::attemptAutologin() directly, without returning boolean from Display::attemptAutologin() in Display::displayServerStarted(), so it will be just:

attemptAutologin();
return;

instead of

bool success = attemptAutologin();
if (success) {
    return;
} else {
    qWarning() << "Autologin failed!";
}

in Display::displayServerStarted() function.

Ok.

@SgAkErRu
Copy link
Contributor Author

SgAkErRu commented Aug 6, 2023

I'm thinking along the lines of emitting slotAuthError within attemptAutologin for instance, though that can be misleading in other ways.

Yes, I agree, because a failure of early checks didn't perform authorization process (through m_auth), so it can be misleading indeed.

I have put handling in separate function, but I have decided to leave Display::attemptAutologin() returning boolean, because it can return false if unable to find autologin session entry. So, true value of Display::attemptAutologin() just means that autologin has been started and this is expressed in the name of the variable autologinStarted instead of success. I think this will emphasized that the autologin can be failed asynchronously.

If not, log that and end autologin attempt, so sddm theme can be loaded instead.
1. If the autologin auth attempt failed for any reason, then start socket server and greeter (launch sddm theme, like as if there was no autologin at all).
2. Early check if the autologin user actually exists in `startAuth` function.
@SgAkErRu
Copy link
Contributor Author

@Vogtinator can you check, please?

src/daemon/Display.cpp Outdated Show resolved Hide resolved
@Vogtinator
Copy link
Contributor

Except for that nitpick it looks good

This check is not specific for autologin

Co-authored-by: Fabian Vogt <fabian@ritter-vogt.de>
src/daemon/Display.cpp Outdated Show resolved Hide resolved
If user is not exist, it will be handle like any other auth error (in slotAuthError)
@Vogtinator Vogtinator merged commit a8e40c5 into sddm:develop Aug 20, 2023
14 checks passed
@SgAkErRu SgAkErRu deleted the check-autologin-user branch August 20, 2023 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants