Initial commit

main
noah metz 2023-12-03 22:04:29 -07:00
parent 9c5b0665d7
commit 05ffd9bf4f
3 changed files with 48 additions and 0 deletions

@ -0,0 +1,8 @@
module main
go 1.21.4
require (
github.com/go-ldap/ldap v3.0.3+incompatible // indirect
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
)

@ -0,0 +1,4 @@
github.com/go-ldap/ldap v3.0.3+incompatible h1:HTeSZO8hWMS1Rgb2Ziku6b8a7qRIZZMHjsvuZyatzwk=
github.com/go-ldap/ldap v3.0.3+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d h1:TxyelI5cVkbREznMhfzycHdkp5cLA7DpE+GKjSslYhM=
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=

@ -0,0 +1,36 @@
package main
import (
"fmt"
"github.com/go-ldap/ldap"
"os"
)
func main() {
var ldap_uri string = os.Args[1]
var ldap_bind_dn string = os.Args[2]
var ldap_bind_pw string = os.Args[3]
var ldap_base_dn string = os.Args[4]
var uid string = os.Args[5]
l, err := ldap.DialURL(ldap_uri)
if err != nil {
panic(err)
}
defer l.Close()
err = l.Bind(ldap_bind_dn, ldap_bind_pw)
if err != nil {
panic(err)
}
search_request := ldap.NewSearchRequest(ldap_base_dn, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, fmt.Sprintf("(&(objectClass=posixAccount)(uid=%s))", uid), []string{"dn", "sshPublicKey"}, nil)
sr, err := l.Search(search_request)
if err != nil {
panic(err)
}
for _, entry := range(sr.Entries) {
fmt.Printf("%v", entry.GetAttributeValue("sshPublicKey"))
}
}