///| Face unlock (docs/face-unlock.md): what the face module in the PAM stack said, for the /// dialog's face row. Chandra's own pam_chandra_face.so says "Face unlock: ..."; Howdy's /// pam_howdy.so says "Attempting facial authentication", "Identified face as ...", and its /// failures as errors. pub(all) enum FaceState { /// No face module spoke in this attempt. NoFace /// Looking for the face; typing the password meanwhile still works (it goes in when PAM asks). Scanning /// Recognized: PAM is finishing. Matched /// Not this time, and why ("Face not recognized"); the password is next. FaceFailed(String) } derive(Eq, Debug) ///| What a PAM message means for face unlock, if it is about it: Some(state), else None. pub fn face_message(m : String, is_error : Bool) -> FaceState? { let t = m.trim(chars=" \n").to_string() let low = t.to_lower() let ours = low.has_prefix("face unlock:") let body = if ours { t[12:].to_string().trim(chars=" ").to_string() } else { t } let lbody = body.to_lower() if ours { if is_error { let why = if lbody.has_prefix("face not recognized") || lbody == "" { "Face not recognized" } else { upper_first(body) } return Some(FaceFailed(why)) } if lbody.has_prefix("recognized") { return Some(Matched) } return Some(Scanning) } // Howdy (pam_howdy.so). if low.has_prefix("attempting facial authentication") || low.has_prefix("attempting face detection") { return Some(Scanning) } if low.has_prefix("identified face as") { return Some(Matched) } if is_error && (low.has_prefix("failure, timeout reached") || low.has_prefix("failure, not a single face")) { return Some(FaceFailed("Face not recognized")) } if is_error && low.has_prefix("face detection image too dark") { return Some(FaceFailed("The camera picture is too dark")) } None } ///| "camera not available" -> "Camera not available". fn upper_first(s : String) -> String { if s.length() == 0 { return s } s[:1].to_string().to_upper() + s[1:].to_string() }