Browse Source

Make it easy to test.

merge-requests/1/head
meskio 5 years ago
parent
commit
a9573a8c0f
  1. 15
      README.md
  2. 25
      examples/data.ldif
  3. 4
      examples/lowry.conf
  4. 7
      ldap/ldap.go
  5. 4
      ldap/user.go
  6. 8
      main.go

15
README.md

@ -0,0 +1,15 @@
Set up a testing environment:
```
sudo apt install slapd
sudo slapadd -n 1 -l examples/data.ldif
```
Run it:
```
make all
./lowry -config examples/lowry.conf
```
Now go to your browser, open http://localhost:8080 and you can login as:
* Usuaria: user
* Contraseña: foobar

25
examples/data.ldif

@ -0,0 +1,25 @@
dn: cn=nss,dc=nodomain
objectClass: organizationalRole
objectClass: simpleSecurityObject
cn: nss
description: LDAP NSS user for user-lookups
userPassword: {SSHA}FHqod3gytvH9MDGhpMV1DKjyU7eO1EDG
structuralObjectClass: organizationalRole
dn: ou=People,dc=nodomain
objectClass: organizationalUnit
ou: People
structuralObjectClass: organizationalUnit
entryUUID: 769a5134-d439-1029-9cfe-a18622f82764
dn: uid=user,ou=People,dc=nodomain
uid: user
cn: User
objectClass: account
objectClass: posixAccount
userPassword: {SSHA}FHqod3gytvH9MDGhpMV1DKjyU7eO1EDG
loginShell: /bin/bash
uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/sindominio/user
gecos: User,,,,Madrid

4
examples/lowry.conf

@ -0,0 +1,4 @@
ldapaddr=localhost:389
ldapdn=dc=nodomain
nsspass=foobar
httpaddr=:8080

7
ldap/ldap.go

@ -7,16 +7,17 @@ import (
// Session to the LDAP server
type Session struct {
conn *ldap.Conn
dc string
}
// Connect to the LDAP server and return a Session
func Connect(addr string, rootdn string, pass string) (*Session, error) {
func Connect(addr string, dc string, pass string) (*Session, error) {
conn, err := ldap.Dial("tcp", addr)
if err != nil {
return nil, err
}
err = conn.Bind(rootdn, pass)
s := &Session{conn}
err = conn.Bind("cn=nss,"+dc, pass)
s := &Session{conn, dc}
return s, err
}

4
ldap/user.go

@ -19,9 +19,9 @@ func (s *Session) LogIn(user string, pass string) error {
func (s *Session) searchUser(user string) (entry *ldap.Entry, err error) {
searchRequest := ldap.NewSearchRequest(
"ou=people,dc=sindominio,dc=net",
"ou=people,"+s.dc,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=account)(uid=%s))", user),
fmt.Sprintf("(&(objectClass=posixAccount)(uid=%s))", user),
[]string{"dn"},
nil,
)

8
main.go

@ -10,15 +10,15 @@ import (
func main() {
var (
addr = flag.String("addr", "localhost:389", "LDAP server address and port")
rootdn = flag.String("rootdn", "", "LDAP root dn")
bindpass = flag.String("pass", "", "LDAP binddn password")
ldapaddr = flag.String("ldapaddr", "localhost:389", "LDAP server address and port")
ldapdc = flag.String("ldapdn", "", "LDAP dc domain")
nsspass = flag.String("nsspass", "", "LDAP nss password")
httpaddr = flag.String("httpaddr", ":8080", "HTTP server bind addr")
)
flag.String(flag.DefaultConfigFlagname, "/etc/lowry.conf", "path to configuration")
flag.Parse()
session, err := ldap.Connect(*addr, *rootdn, *bindpass)
session, err := ldap.Connect(*ldapaddr, *ldapdc, *nsspass)
if err != nil {
log.Fatal(err)
}

Loading…
Cancel
Save