* Rename fsldap to efsldap

* Use gopkg.in/ini.v1 over github.com/joho/godotenv
* Fix typos

Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
This commit is contained in:
2026-01-07 16:37:02 -03:00
parent 0677061406
commit e4d9b92061
13 changed files with 147 additions and 69 deletions

View File

@@ -1,5 +0,0 @@
SMTP_HOSTNAME = "localhost"
SMTP_PORT = "25"
SMTP_DOMAIN = "example.com"
LDAP_BASE = "dn=example,dn=com"
LDAP_UID = "cn"

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/efsldap

19
COPYING
View File

@@ -1,6 +1,7 @@
Discordian Public License 2.3 (DPL-2.3)
All Rites Reversed (ĸ) 3189 Czar <czar at kalli dot st>
All Rites Reversed (k) 3192 Shin'ya Minazuki <shinyoukai at laidback dot moe>
Permission is hereby granted, to any person obtaining a copy of this
material without restriction, including but not limited the rights to
@@ -9,4 +10,20 @@ copies of the material, subject to the following conditions:
YOU AGREE THAT THERE IS NO GODDESS BUT GODDESS AND SHE IS YOUR GODDESS &
THAT THERE IS NO ERISIAN MOVEMENT BUT THE ERISIAN MOVEMENT AND IT IS THE
ERISIAN MOVEMENT.
ERISIAN MOVEMENT.
---
Minazuki License
Copyright (c) 2026 Shin'ya Minazuki <shinyoukai at laidback dot moe>
You can do as you please with these files so long as you keep this notice
intact and make no false claims about the ownership of said files.
Should you believe this is useful to you, feel free to reach out
the author via any of the available contact methods.
There is no express and/or implied warranties whatsoever, so
whoever makes you think otherwise, is at fault for believing
it is.

View File

@@ -1,7 +1,9 @@
BINARY_NAME = fsldap
GO ?= go
GOFLAGS ?= -v -buildvcs=false -buildmode=exe
build:
go build -v
run: build
./$(BINARY_NAME)
${GO} build ${GOFLAGS}
clean:
rm -f esfldap
run:
./efsldap

View File

@@ -1,4 +1,4 @@
#+TITLE: Fake SMTP LDAP Server
#+TITLE: Enhanced Fake SMTP LDAP Server
#+AUTHOR: czar
A LDAP server that use SMTP as authentication source
@@ -8,13 +8,13 @@ A LDAP server that use SMTP as authentication source
- LDAP SEARCH
* Build
fsldap is a written in Go, so you will need to install the Golang compiler
efsldap is written in Go, so you will need to install the Golang compiler
#+BEGIN_QUOTE
$ make build
#+END_QUOTE
* Configuration
copy the =.env.default= to =.env= and set your variables accordly
copy the =efsldap.ini= to =/usr/pkg/etc/efsldap.ini= and set your variables accordly
* Running
#+BEGIN_QUOTE

43
config/config.go Normal file
View File

@@ -0,0 +1,43 @@
package config
import (
"errors"
"log"
"os"
"gopkg.in/ini.v1"
)
var Config struct {
LDAPBase string
LDAPUID string
SMTPDomain string
SMTPHost string
SMTPPort string
}
var (
ConfigPath string
)
func ConfInit() {
if _, err := os.Stat(ConfigPath); errors.Is(err, os.ErrNotExist) {
log.Fatal(err)
}
Parse(ConfigPath)
}
func Parse(fn string) error {
cfg, err := ini.Load(fn)
if err != nil {
return err
}
Config.LDAPBase = cfg.Section("").Key("ldap_base").String()
Config.LDAPUID = cfg.Section("").Key("ldap_uid").String()
Config.SMTPDomain = cfg.Section("").Key("smtp_domain").String()
Config.SMTPHost = cfg.Section("").Key("smtp_host").String()
Config.SMTPPort = cfg.Section("").Key("smtp_port").String()
return nil
}

5
efsldap.ini Normal file
View File

@@ -0,0 +1,5 @@
ldap_base = "dn=example,dn=com"
ldap_uid = "cn"
smtp_domain = "example.com"
smtp_host = "localhost"
smtp_port = "25"

8
go.mod
View File

@@ -1,9 +1,11 @@
module gt.kalli.st/czar/fsldap
module git.laidback.moe/YakumoLabs/efsldap
go 1.14
require (
github.com/joho/godotenv v1.3.0 // indirect
github.com/lor00x/goldap v0.0.0-20180618054307-a546dffdd1a3 // indirect
github.com/lor00x/goldap v0.0.0-20180618054307-a546dffdd1a3
github.com/spf13/pflag v1.0.10
github.com/stretchr/testify v1.11.1 // indirect
github.com/vjeantet/ldapserver v1.0.1
gopkg.in/ini.v1 v1.67.0
)

25
go.sum
View File

@@ -1,6 +1,27 @@
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/lor00x/goldap v0.0.0-20180618054307-a546dffdd1a3 h1:wIONC+HMNRqmWBjuMxhatuSzHaljStc4gjDeKycxy0A=
github.com/lor00x/goldap v0.0.0-20180618054307-a546dffdd1a3/go.mod h1:37YR9jabpiIxsb8X9VCIx8qFOjTDIIrIHHODa8C4gz0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/vjeantet/ldapserver v1.0.1 h1:3z+TCXhwwDLJC3pZCNbuECPDqC2x1R7qQQbswB1Qwoc=
github.com/vjeantet/ldapserver v1.0.1/go.mod h1:YvUqhu5vYhmbcLReMLrm/Tq3S7Yj43kSVFvvol6Lh6k=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -8,13 +8,16 @@ import (
"github.com/lor00x/goldap/message"
ldap "github.com/vjeantet/ldapserver"
"gt.kalli.st/czar/fsldap/utils"
"git.laidback.moe/YakumoLabs/efsldap/config"
"git.laidback.moe/YakumoLabs/efsldap/utils"
)
var smtpHost = utils.Env("SMTP_HOSTNAME")
var smtpPort = utils.Env("SMTP_PORT")
var base = utils.Env("LDAP_BASE")
var smtpHostPort = fmt.Sprintf("%s:%s", smtpHost,smtpPort)
var (
base = config.Config.LDAPBase
smtpHost = config.Config.SMTPHost
smtpPort = config.Config.SMTPPort
smtpHostPort = fmt.Sprintf("%s:%s", smtpHost,smtpPort)
)
var tlsconfig = &tls.Config {
InsecureSkipVerify: true,

View File

@@ -7,12 +7,28 @@ import (
"syscall"
ldap "github.com/vjeantet/ldapserver"
"gt.kalli.st/czar/fsldap/handler"
cfg "git.laidback.moe/YakumoLabs/efsldap/config"
"git.laidback.moe/YakumoLabs/efsldap/handler"
flag "github.com/spf13/pflag"
)
var (
configPath string
)
func main() {
flag.StringVarP(&configPath, "config", "c", "", "Path to configuration file")
flag.Parse()
if configPath != "" {
cfg.ConfigPath = configPath
cfg.ConfInit()
} else {
log.Fatal("Unable to load configuration file")
}
server := ldap.NewServer()
routes := ldap.NewRouteMux()
routes.Bind(handler.Bind)
@@ -22,7 +38,7 @@ func main() {
server.Handle(routes)
log.Print("Starting FSLDAP server...")
log.Print("Starting EFSLDAP server...")
go func(){
err := server.ListenAndServe("127.0.0.1:389")
if err != nil{

View File

@@ -1,39 +0,0 @@
package utils
import (
"log"
"os"
"github.com/joho/godotenv"
)
var SmtpHostname, SmtpPort, Domain, Base, Uid string
var BaseLenght, UidLenght int
func init(){
loadEnv()
}
func loadEnv(){
log.Print("Loading .env file...")
err := godotenv.Load()
if err != nil {
log.Print("error loading .env file")
}
Domain = Env("SMTP_DOMAIN")
Base = Env("LDAP_BASE")
Uid = Env("LDAP_UID")
BaseLenght = len(Base) + 1
UidLenght = len(Uid) + 1
log.Print("Base ",Base," BaseLenght ",BaseLenght)
}
func Env(name string) string{
envVar := os.Getenv(name)
if envVar == "" {
log.Fatalf("error getting %s env variable", name)
}
return envVar
}

View File

@@ -3,6 +3,18 @@ package utils
import (
"fmt"
"strings"
"git.laidback.moe/YakumoLabs/efsldap/config"
)
var (
Base = config.Config.LDAPBase
Domain = config.Config.SMTPDomain
Uid = config.Config.LDAPUID
)
var (
BaseLength = len(Base) + 1
UidLength = len(Uid) + 1
)
func GetMail(user string) string {
@@ -14,11 +26,11 @@ func GetLdapName(user string) string {
}
func GetUser(name string) string {
endIndex := len(name) - BaseLenght
endIndex := len(name) - BaseLength
if endIndex < 0 {
return ""
}
user := name[UidLenght:endIndex]
user := name[UidLength:endIndex]
user = strings.TrimSuffix(user, "@"+Domain)
@@ -26,7 +38,7 @@ func GetUser(name string) string {
}
func GetSearchUser(name string) string {
startIndex := UidLenght + 1
startIndex := UidLength + 1
endIndex := len(name) - 1
if endIndex < 0 {
return ""