add api and tool for query mxpassfiles, fixes
This commit is contained in:
parent
41fa795971
commit
8df08611a9
7 changed files with 95 additions and 20 deletions
|
|
@ -87,28 +87,20 @@ func parseLine(line string) *Entry {
|
|||
}
|
||||
}
|
||||
|
||||
func isWild(s string) bool {
|
||||
if s == "" || s == "*" {
|
||||
func superCMP(fileitem, filteritem string) bool {
|
||||
if filteritem == "*" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func superCMP(s1, s2 string) bool {
|
||||
if isWild(s1) || isWild(s2) {
|
||||
return true
|
||||
}
|
||||
//fmt.Printf("sCMP: '%s' '%s'\n", s1, s2)
|
||||
return s1 == s2
|
||||
return fileitem == filteritem
|
||||
}
|
||||
|
||||
// FindPassword finds the password for the provided synapsehost, localpart, and domain. An empty
|
||||
// string will be returned if no match is found.
|
||||
func (pf *Passfile) FindPassword(matrixhost, localpart, domain string) string {
|
||||
for _, e := range pf.Entries {
|
||||
if (e.Matrixhost == "*" || e.Matrixhost == matrixhost) &&
|
||||
(e.Localpart == "*" || e.Localpart == localpart) &&
|
||||
(e.Domain == "*" || e.Domain == domain) {
|
||||
if superCMP(e.Matrixhost, matrixhost) &&
|
||||
superCMP(e.Localpart, localpart) &&
|
||||
superCMP(e.Domain, domain) {
|
||||
return e.Token
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,6 +170,20 @@ func cliv0_serverinfo(url *C.char) *C.char {
|
|||
return C.CString(result)
|
||||
}
|
||||
|
||||
//export cliv0_mxpassitem
|
||||
func cliv0_mxpassitem(mxpassfile_path *C.char, url *C.char, localpart *C.char, domain *C.char) *C.char {
|
||||
item, err := mxutils.GetMXPassItem(C.GoString(mxpassfile_path), C.GoString(url), C.GoString(localpart), C.GoString(domain))
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
out, err := json.Marshal(item)
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
s := string(out)
|
||||
return C.CString(s)
|
||||
}
|
||||
|
||||
/*
|
||||
high level api, supports multiple clients
|
||||
the same handler can be attached to multiple clients
|
||||
|
|
|
|||
20
libmxclient/mxutils/mxpass.go
Normal file
20
libmxclient/mxutils/mxpass.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2026 saces@c-base.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
package mxutils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"mxclientlib/determinant/mxpassfile"
|
||||
)
|
||||
|
||||
func GetMXPassItem(mxpassfile_path string, url string, localpart string, domain string) (*mxpassfile.Entry, error) {
|
||||
pf, err := mxpassfile.ReadPassfile(mxpassfile_path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e := pf.FindPasswordFill(url, localpart, domain)
|
||||
if e == nil {
|
||||
return nil, errors.New("no item found.")
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue