android/ui: fix infinite recursion in custom login (#371)

Updates tailscale/tailscale#11731

The MDM logic was infinitely recursing.  The custom control url login
handler now does what the other functions do and calls into login
with a set of pre-populated prefs.  If MDM specifies a custom login
server, we force that, regardless of anything the user specified.

This behaviour matches macOS.

Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
pull/366/head
Jonathan Nobels 1 month ago committed by GitHub
parent 31b0ec8865
commit 45fd2e0661
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -90,11 +90,6 @@ open class IpnViewModel : ViewModel() {
authKey: String? = null,
completionHandler: (Result<Unit>) -> Unit = {}
) {
MDMSettings.loginURL.flow.value?.let {
Log.d(TAG, "Using MDM derived control URL: $it")
loginWithCustomControlURL(it, completionHandler)
return
}
val loginAction = {
Client(viewModelScope).startLoginInteractive { result ->
@ -111,8 +106,18 @@ open class IpnViewModel : ViewModel() {
}
}
maskedPrefs?.let { prefs ->
Client(viewModelScope).editPrefs(prefs) { result ->
// If an MDM control URL is set, we will always use that in lieu of anything the user sets.
var prefs = maskedPrefs
val mdmControlURL = MDMSettings.loginURL.flow.value
if (mdmControlURL != null) {
prefs = prefs ?: Ipn.MaskedPrefs()
prefs.ControlURL = mdmControlURL
Log.d(TAG, "Overriding control URL with MDM value: $mdmControlURL")
}
prefs?.let {
Client(viewModelScope).editPrefs(it) { result ->
result.onFailure { completionHandler(Result.failure(it)) }.onSuccess { startAction() }
}
} ?: run { startAction() }
@ -128,18 +133,9 @@ open class IpnViewModel : ViewModel() {
controlURL: String,
completionHandler: (Result<Unit>) -> Unit = {}
) {
val fail: (Throwable) -> Unit = { completionHandler(Result.failure(it)) }
// The flow for logging in with a custom control URL is to add a profile,
// call start with prefs that include the control URL, then
// start an interactive login.
Client(viewModelScope).addProfile { profile ->
profile.onFailure(fail).onSuccess {
val prefs = Ipn.MaskedPrefs()
prefs.ControlURL = controlURL
login(prefs, authKey = null, completionHandler)
}
}
val prefs = Ipn.MaskedPrefs()
prefs.ControlURL = controlURL
login(prefs, completionHandler = completionHandler)
}
fun logout(completionHandler: (Result<String>) -> Unit = {}) {

Loading…
Cancel
Save