コード例 #1
0
ファイル: add.go プロジェクト: jsimonetti/ldapserv
func (l *LdifBackend) Add(w ldap.ResponseWriter, m *ldap.Message) {
	r := m.GetAddRequest()
	// Handle Stop Signal (server stop / client disconnected / Abandoned request....)
	select {
	case <-m.Done:
		l.Log.Debug("Leaving Add... stop signal")
		return
	default:
	}

	l.Log.Debug("Adding entry", log.Ctx{"entry": r.Entry()})

	entry := ldif{dn: string(r.Entry())}

	for _, attribute := range r.Attributes() {
		for _, attributeValue := range attribute.Vals() {
			if isValueBinary([]byte(attributeValue)) {
				value := base64.StdEncoding.EncodeToString([]byte(attributeValue))
				entry.attr = append(entry.attr, attr{name: string(attribute.Type_()), content: []byte(value), atype: ATTR_TYPE_BINARY})
				l.Log.Debug("attribute", log.Ctx{"type": attribute.Type_(), "value": string(value), "atype": "binary"})
			} else {
				entry.attr = append(entry.attr, attr{name: string(attribute.Type_()), content: []byte(attributeValue), atype: ATTR_TYPE_TEXT})
				l.Log.Debug("attribute", log.Ctx{"type": attribute.Type_(), "value": string(attributeValue), "atype": "string"})
			}
		}
	}
	if ok, err := l.saveEntry(entry); ok {
		l.ldifs = append(l.ldifs, entry)
		res := ldap.NewAddResponse(ldap.LDAPResultSuccess)
		w.Write(res)
		return
	} else {
		l.Log.Debug("Add entry error", log.Ctx{"error": err})
	}
	res := ldap.NewAddResponse(ldap.LDAPResultOperationsError)
	w.Write(res)
}
コード例 #2
0
ファイル: add.go プロジェクト: jsimonetti/ldapserv
func (d *DebugBackend) Add(w ldap.ResponseWriter, m *ldap.Message) {
	r := m.GetAddRequest()
	dump(r)
	res := ldap.NewAddResponse(ldap.LDAPResultOperationsError)
	w.Write(res)
}