|
|
@ -6,7 +6,19 @@ import (
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func usage(code int, err error) {
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
os.Stderr.WriteString(fmt.Sprintf("error %s\n", err))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Stderr.WriteString(fmt.Sprintf("usage: %s [uri] [bind_dn] [bind_pw] [base_dn] [uid]\n", os.Args[0]))
|
|
|
|
|
|
|
|
os.Exit(code)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
if len(os.Args) != 6 {
|
|
|
|
|
|
|
|
usage(1, nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ldap_uri string = os.Args[1]
|
|
|
|
var ldap_uri string = os.Args[1]
|
|
|
|
var ldap_bind_dn string = os.Args[2]
|
|
|
|
var ldap_bind_dn string = os.Args[2]
|
|
|
|
var ldap_bind_pw string = os.Args[3]
|
|
|
|
var ldap_bind_pw string = os.Args[3]
|
|
|
@ -15,19 +27,20 @@ func main() {
|
|
|
|
|
|
|
|
|
|
|
|
l, err := ldap.DialURL(ldap_uri)
|
|
|
|
l, err := ldap.DialURL(ldap_uri)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
usage(2, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
defer l.Close()
|
|
|
|
defer l.Close()
|
|
|
|
|
|
|
|
|
|
|
|
err = l.Bind(ldap_bind_dn, ldap_bind_pw)
|
|
|
|
err = l.Bind(ldap_bind_dn, ldap_bind_pw)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
usage(3, 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)
|
|
|
|
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)
|
|
|
|
sr, err := l.Search(search_request)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
usage(4, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, entry := range(sr.Entries) {
|
|
|
|
for _, entry := range(sr.Entries) {
|
|
|
|