Exemplo n.º 1
0
// FIXME : support all kind of option (int, int*, ...) should take care of all return type for ldap_get_option
func (self *Ldap) GetOption(opt int) (val int, err error) {

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

	if rv == LDAP_OPT_SUCCESS {
		return val, nil
	}

	return 0, errors.New(fmt.Sprintf("LDAP::GetOption() error (%d) : %s", rv, ErrorToString(int(rv))))
}
Exemplo n.º 2
0
func GetGlobalOption(opt int) (val interface{}, err error) {
	var rv int
	switch opt {
	case LDAP_OPT_X_TLS_CACERTFILE:
		val_c := C.CString("")
		defer C.free(unsafe.Pointer(val_c))
		rv = int(C.ldap_get_option(nil, C.int(opt), unsafe.Pointer(&val_c)))
		if rv == LDAP_OPT_SUCCESS {
			return C.GoString((*C.char)(val_c)), nil
		}
	case LDAP_OPT_PROTOCOL_VERSION, LDAP_OPT_X_TLS_REQUIRE_CERT:
		var val_ int
		rv = int(C.ldap_get_option(nil, C.int(opt), unsafe.Pointer(&val_)))
		if rv == LDAP_OPT_SUCCESS {
			return val_, nil
		}
	}

	return 0, errors.New(fmt.Sprintf("LDAP::GetGlobalOption() error (%d) : %s", rv,
		ErrorToString(int(rv))))
}
Exemplo n.º 3
0
// FIXME : support all kind of option (int, int*, ...) should take care of all return type for ldap_get_option
func (self *Ldap) GetOption(opt int) (val interface{}, err error) {
	// API: int ldap_get_option (LDAP *ld,int option, LDAP_CONST void *invalue));
	var rv int
	switch opt {
	case LDAP_OPT_X_TLS_CACERTFILE:
		val_c := C.CString("")
		defer C.free(unsafe.Pointer(val_c))
		rv = int(C.ldap_get_option(self.conn, C.int(opt), unsafe.Pointer(&val_c)))
		if rv == LDAP_OPT_SUCCESS {
			return C.GoString((*C.char)(val_c)), nil
		}
	case LDAP_OPT_PROTOCOL_VERSION, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_ERROR_NUMBER:
		var val_ int
		rv = int(C.ldap_get_option(self.conn, C.int(opt), unsafe.Pointer(&val_)))
		if rv == LDAP_OPT_SUCCESS {
			return val_, nil
		}
	}

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