Example #1
0
func SetGlobalOption(opt int, val interface{}) error {
	var rv int = -1
	switch val.(type) {
	case int:
		x := val.(int)
		rv = int(C.ldap_set_option(nil, C.int(opt), unsafe.Pointer(&x)))
	case string:
		x := C.CString(val.(string))
		defer C.free(unsafe.Pointer(x))
		rv = int(C.ldap_set_option(nil, C.int(opt), unsafe.Pointer(&x)))
	default:
		return nil
	}
	if rv == LDAP_OPT_SUCCESS {
		return nil
	}
	return errors.New(fmt.Sprintf("LDAP::SetGlobalOption() error (%d) : %s", int(rv), ErrorToString(int(rv))))
}
Example #2
0
// FIXME : support all kind of option (int, int*, ...)
func (self *Ldap) SetOption(opt int, val interface{}) error {
	// API: ldap_set_option (LDAP *ld,int option, LDAP_CONST void *invalue));
	var rv int
	switch val.(type) {
	case int:
		x := val.(int)
		rv = int(C.ldap_set_option(nil, C.int(opt), unsafe.Pointer(&x)))
	case string:
		x := C.CString(val.(string))
		defer C.free(unsafe.Pointer(x))
		rv = int(C.ldap_set_option(nil, C.int(opt), unsafe.Pointer(x)))
	default:
		return nil
	}
	if rv == LDAP_OPT_SUCCESS {
		return nil
	}

	return errors.New(fmt.Sprintf("LDAP::SetOption() error (%d) : %s", int(rv), ErrorToString(int(rv))))
}
Example #3
0
// FIXME : support all kind of option (int, int*, ...)
func (self *Ldap) SetOption(opt int, val int) error {

	// API: ldap_set_option (LDAP *ld,int option, LDAP_CONST void *invalue));
	rv := C.ldap_set_option(self.conn, C.int(opt), unsafe.Pointer(&val))

	if rv == LDAP_OPT_SUCCESS {
		return nil
	}

	return errors.New(fmt.Sprintf("LDAP::SetOption() error (%d) : %s", int(rv), ErrorToString(int(rv))))
}