示例#1
0
func ModifyTeamEmail(action int, arg ManagerEmailArg, reply *ManagerEmailReply) error {
	conn, err := InitConnection(&arg.ManagerAuthArg)
	if err != nil {
		return err
	}

	if !TeamExists(arg.Team, &arg.ManagerAuthArg) {
		return errors.New("Team Does Not Exist")
	}

	if action == ldap.ModDelete && !EmailExists(arg.Email, arg.Team, &arg.ManagerAuthArg) {
		return errors.New("Email does not exist.")
	} else if action == ldap.ModAdd && EmailExists(arg.Email, arg.Team, &arg.ManagerAuthArg) {
		return errors.New("Email already exists.")
	}

	var modDNs []string = []string{aldap.TeamCommonName + "=" + arg.Team + "," + aldap.TeamOu}
	var Attrs []string = []string{"email"}
	var vals []string = []string{arg.Email}
	modReq := ldap.NewModifyRequest(modDNs[0])
	mod := ldap.NewMod(uint8(action), Attrs[0], vals)
	modReq.AddMod(mod)
	if err := conn.Modify(modReq); err != nil {
		return err
	}

	return nil
}
示例#2
0
func ModifyTeamAdmin(action int, arg ManagerModifyTeamAdminArg, reply *ManagerModifyTeamAdminReply) error {
	conn, err := InitConnection(&arg.ManagerAuthArg)
	if err != nil {
		return err
	}

	if !UserExists(arg.User, &arg.ManagerAuthArg) {
		return errors.New("User does not exist")
	}

	if !TeamExists(arg.Team, &arg.ManagerAuthArg) {
		return errors.New("Team Does Not Exist")
	}

	var modDNs []string = []string{aldap.TeamCommonName + "=" + arg.Team + "," + aldap.TeamOu}
	var Attrs []string = []string{aldap.TeamAdminAttr}
	var vals []string = []string{aldap.UserCommonName + "=" + arg.User + "," + aldap.UserOu}
	modReq := ldap.NewModifyRequest(modDNs[0])
	mod := ldap.NewMod(uint8(action), Attrs[0], vals)
	modReq.AddMod(mod)
	if err := conn.Modify(modReq); err != nil {
		return err
	}

	return nil
}
示例#3
0
func TestLocalControlPermissiveModifyRequest(t *testing.T) {
	fmt.Printf("ControlPermissiveModifyRequest: starting...\n")
	l := ldap.NewLDAPConnection(server, port)
	err := l.Connect()
	if err != nil {
		t.Error(err)
		return
	}
	defer l.Close()

	err = l.Bind(binddn, passwd)
	if err != nil {
		t.Error(err)
		return
	}

	addReq := ldap.NewAddRequest(addDNs[0])
	for _, attr := range addAttrs {
		addReq.AddAttribute(&attr)
	}
	fmt.Printf("Adding: %s\n", addDNs[0])
	err = l.Add(addReq)
	if err != nil {
		t.Errorf("Add : %s : %s\n", addDNs[0], err)
		return
	}

	modreq := ldap.NewModifyRequest(addDNs[0])
	mod := ldap.NewMod(ldap.ModAdd, "description", []string{"aaa"})
	modreq.AddMod(mod)
	fmt.Println(modreq)
	err = l.Modify(modreq)
	if err != nil {
		t.Errorf("Modify : %s : %s\n", addDNs[0], err)
		return
	}

	mod = ldap.NewMod(ldap.ModAdd, "description", []string{"aaa", "bbb", "ccc"})
	modreq = ldap.NewModifyRequest(addDNs[0])
	modreq.AddMod(mod)
	control := ldap.NewControlString(ldap.ControlTypePermissiveModifyRequest, true, "")
	fmt.Println(control.String())
	modreq.AddControl(control)
	fmt.Println(modreq)
	err = l.Modify(modreq)
	if err != nil {
		t.Errorf("Modify (Permissive): %s : %s\n", addDNs[0], err)
		return
	}

	mod = ldap.NewMod(ldap.ModAdd, "description", []string{"aaa", "bbb", "ccc", "ddd"})
	modreq = ldap.NewModifyRequest(addDNs[0])
	modreq.AddMod(mod)
	control = ldap.NewControlPermissiveModifyRequest(false)
	fmt.Println(control.String())
	modreq.AddControl(control)
	fmt.Println(modreq)
	err = l.Modify(modreq)
	if err != nil {
		t.Errorf("Modify (Permissive): %s : %s\n", addDNs[0], err)
		return
	}

	fmt.Printf("Deleting: %s\n", addDNs[0])
	delRequest := ldap.NewDeleteRequest(addDNs[0])
	err = l.Delete(delRequest)

	if err != nil {
		t.Errorf("Delete : %s : %s\n", addDNs[0], err)
		return
	}
}
示例#4
0
func TestLocalControlMatchedValuesRequest(t *testing.T) {
	fmt.Printf("LocalControlMatchedValuesRequest: starting...\n")
	l := ldap.NewLDAPConnection(server, port)
	err := l.Connect()
	if err != nil {
		t.Error(err)
		return
	}
	defer l.Close()

	err = l.Bind(binddn, passwd)
	if err != nil {
		t.Error(err)
		return
	}

	addReq := ldap.NewAddRequest(addDNs[0])
	for _, attr := range addAttrs {
		addReq.AddAttribute(&attr)
	}
	fmt.Printf("Adding: %s\n", addDNs[0])
	err = l.Add(addReq)
	if err != nil {
		t.Errorf("Add : %s : %s\n", addDNs[0], err)
		return
	}

	fmt.Printf("Modify: %s = {aaa, bbb, ccc}\n", "description")
	mod := ldap.NewMod(ldap.ModAdd, "description", []string{"aaa", "bbb", "ccc", "aabb"})
	modreq := ldap.NewModifyRequest(addDNs[0])
	modreq.AddMod(mod)
	err = l.Modify(modreq)
	if err != nil {
		t.Errorf("Modify: %s : %s\n", addDNs[0], err)
		return
	}

	control := ldap.NewControlMatchedValuesRequest(true, "(description=aaa)")
	fmt.Println(control.String())
	fmt.Printf("Search: (objectclass=*), (description=aaa) via MatchedValuesRequest\n")
	search_request := ldap.NewSimpleSearchRequest(
		addDNs[0],
		ldap.ScopeBaseObject,
		"(objectclass=*)",
		[]string{"description"},
	)
	search_request.AddControl(control)
	//l.Debug = true
	sr, err := l.Search(search_request)
	if err != nil {
		t.Errorf("Search: %s : %s\n", addDNs[0], err)
		return
	}
	//l.Debug = false
	fmt.Println("Search Result:")
	fmt.Print(sr)

	control = ldap.NewControlMatchedValuesRequest(true, "(description=a*)")
	fmt.Println(control.String())
	fmt.Printf("Search: (objectclass=*), (description=a*) via MatchedValuesRequest\n")
	search_request = ldap.NewSimpleSearchRequest(
		addDNs[0],
		ldap.ScopeBaseObject,
		"(objectclass=*)",
		[]string{"description"},
	)
	search_request.AddControl(control)
	//l.Debug = true
	sr, err = l.Search(search_request)
	if err != nil {
		t.Errorf("Search: %s : %s\n", addDNs[0], err)
		return
	}
	//l.Debug = false
	fmt.Println("Search Result:")
	fmt.Print(sr)

	fmt.Printf("Deleting: %s\n", addDNs[0])
	delRequest := ldap.NewDeleteRequest(addDNs[0])
	err = l.Delete(delRequest)

	if err != nil {
		t.Errorf("Delete : %s : %s\n", addDNs[0], err)
		return
	}
}