{"record":{"id":"56692e8d5441fcb8","repo":"juicedata/juicefs","slug":"ldap-search-sw-failed-d","errorCode":null,"errorMessage":"ldap_search_sW failed: %d","messagePattern":"ldap_search_sW failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/win/ldap.go","lineNumber":119,"sourceCode":"\t}\n\tattrPtr, err := windows.UTF16PtrFromString(attribute)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tattrs := []uintptr{uintptr(unsafe.Pointer(attrPtr)), 0}\n\n\tvar msg uintptr\n\tr1, _, _ := procLdapSearchSW.Call(\n\t\thandle,\n\t\tuintptr(unsafe.Pointer(basePtr)),\n\t\tuintptr(scope),\n\t\tuintptr(unsafe.Pointer(filterPtr)),\n\t\tuintptr(unsafe.Pointer(&attrs[0])),\n\t\t0,\n\t\tuintptr(unsafe.Pointer(&msg)),\n\t)\n\tif int32(r1) != LDAP_SUCCESS {\n\t\treturn \"\", fmt.Errorf(\"ldap_search_sW failed: %d\", r1)\n\t}\n\tdefer procLdapMsgFree.Call(msg)\n\n\tentry, _, _ := procLdapFirstEntry.Call(handle, msg)\n\tif entry == 0 {\n\t\treturn \"\", fmt.Errorf(\"no entries found\")\n\t}\n\tvals, _, _ := procLdapGetValuesW.Call(handle, entry, uintptr(unsafe.Pointer(attrPtr)))\n\tif vals == 0 {\n\t\treturn \"\", fmt.Errorf(\"no attribute values\")\n\t}\n\tdefer procLdapValueFreeW.Call(vals)\n\tcnt, _, _ := procLdapCountValuesW.Call(vals)\n\tif cnt == 0 {\n\t\treturn \"\", fmt.Errorf(\"no attribute values\")\n\t}\n\tfirstPtr := *(*uintptr)(unsafe.Pointer(vals))\n\tvalue := windows.UTF16PtrToString((*uint16)(unsafe.Pointer(firstPtr)))","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/win/ldap.go#L101-L137","documentation":"LdapGetValue issues ldap_search_sW against the connected directory with the given base DN, filter, and attribute list. If the search call returns a non-LDAP_SUCCESS result, it returns \"ldap_search_sW failed: %d\" with the LDAP status code. Used by LdapGetDefaultNamingContext and LdapGetTrustPosixOffset during trust-POSIX-offset initialization.","triggerScenarios":"ldap_search_sW returns an error status: bad base DN (e.g. wrong defaultNamingContext), insufficient rights to read the trustedDomain objects, size/scope limits, or the DC dropped the connection.","commonSituations":"Querying CN=Configuration or trusted domain objects with an account lacking read permission; malformed LDAP filter; base DN with unescaped special characters; expired session after long idle.","solutions":["Decode the LDAP status code (e.g. 32=no such object, 50=insufficient rights) and act on it.","Verify the base DN and filter strings, especially escaping of special characters.","Run under an account with rights to read trustedDomain objects in the Configuration NC.","Reconnect (LdapClose + LdapConnect) if the session may have timed out."],"exampleFix":"// before\nr1, _, _ := procLdapSearchSW.Call(...)\nif int32(r1) != LDAP_SUCCESS {\n    return \"\", fmt.Errorf(\"ldap_search_sW failed: %d\", r1)\n}\n// after (caller-side retry on transient codes)\nif int32(r1) == 81 || int32(r1) == 85 { // server down / busy\n    handle, err = LdapConnect(host); /* retry once */\n}","handlingStrategy":"try-catch","validationCode":"// validate filter/base before calling\nif baseDN == \"\" || !strings.Contains(filter, \"=\") {\n    return errors.New(\"invalid LDAP base DN or filter\")\n}","typeGuard":null,"tryCatchPattern":"val, err := LdapGetDefaultNamingContext(handle)\nif err != nil {\n    var code int\n    if n, _ := fmt.Sscanf(err.Error(), \"ldap_search_sW failed: %d\", &code); n == 1 {\n        log.Printf(\"ldap search status %d\", code) // 32=bad DN, 50=rights\n    }\n    return err\n}","preventionTips":["Escape DN/filter special characters before building queries.","Grant the querying identity read access to trustedDomain objects.","Reconnect on session-expiry style LDAP codes before retrying."],"tags":["windows","ldap","active-directory","query"],"backgroundTag":"database-query-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}