{"id":21847559,"url":"https://github.com/scribd/simpleldapclient","last_synced_at":"2025-08-21T12:13:43.935Z","repository":{"id":66239623,"uuid":"221962558","full_name":"scribd/simpleldapclient","owner":"scribd","description":"Simple LDAP client that abstracts many of the more LDAP-ish operations into functions.","archived":false,"fork":false,"pushed_at":"2019-11-15T18:07:33.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-21T17:19:54.077Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scribd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-15T16:28:22.000Z","updated_at":"2019-12-06T21:24:52.000Z","dependencies_parsed_at":"2023-02-20T16:32:00.525Z","dependency_job_id":null,"html_url":"https://github.com/scribd/simpleldapclient","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/scribd/simpleldapclient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scribd%2Fsimpleldapclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scribd%2Fsimpleldapclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scribd%2Fsimpleldapclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scribd%2Fsimpleldapclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scribd","download_url":"https://codeload.github.com/scribd/simpleldapclient/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scribd%2Fsimpleldapclient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271478008,"owners_count":24766424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-27T23:18:38.180Z","updated_at":"2025-08-21T12:13:43.892Z","avatar_url":"https://github.com/scribd.png","language":"Go","readme":"# SimpleLdapClient\n\nLDAP Directories are often quite useful beasts, but automating against them can be painful.\n\nThe syntax and methodology for managing info in the tree is often something a developer doesn't have, and to be fair, doesn't want.\n\nSimpleLdapClient attempts to abstract much of that behind basic functions that do what the developer intends without requiring overmuch understanding of LDAP itself.\n\nThese libraries presume a very basic setup according to RFC 2307, which means that group membership is stored in the group object as memberUid attributes, not in the user objects as memberOf fields.\n\nUnder this design, one would search for the groups for a user via the following search:\n\n    ldapsearch -x \"(\u0026(objectClass=posixGroup)(memberUid=\u003cname\u003e))\" cn\n    \nand would expect a list of CN's that correspond to groups the user is a member of.\n\nThis library assumes a pretty standard layout, the admin username is 'admin', groups are in an OU called 'groups', users are in an OU named 'users'.\n\nUndoubtedly this could use further abstraction, but hey, it's a 'simple' client that if nothing else can be used as a jumping off point for your own awesomeitude.\n\n## Examples\n\nCreate a client and connect:\n\n\tlc, err := NewSimpleLdapClient(\"ldap://somedirectory.com\", \"dc=examle,dc=com\", 389, false, nil)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create client: %s\", err)\n\t}\n\n\terr = lc.Connect()\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to connect to ldap server\")\n\t}\n\nLook up email for a username:\n\n\tuserEmail, err := lc.EmailForUsername(\"bob\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Error retrieving email for username 'bob': %s\", err)\n\t}\n\t\n\t\nLook up a user's SSH Public Key:\n\n\tuserPubKey, err := lc.PubkeyForUsername(\"bob\")\n\n\tif err != nil {\n\t\tlog.Fatalf(\"Error retrieving pubkey for username 'bob': %s\", err)\n\t}\n\t\nCheck to see that a user is in a group:\n\n\nSee if a group already exists:\n\n\tok, err := lc.GroupExists(groupname)\n\tif err != nil {\n\t\tlog.Printf(\"error searching for group %s in ldap: %s\", groupname, err)\n\t\tt.Fail()\n\t}\n\n\tassert.True(t, ok, \"Group successfully added to ldap\")\n\n\nAdd a group:\n\n\terr = lc.AddGroup(groupname, gid)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to add group %s to ldap: %s\", groupname, err)\n\t}\n\nAdd a user to a group:\n\n\tusername := \"fred\"\n\n\terr = lc.AddUserToGroup(username, groupname)\n\tif err != nil {\n\t\tlog.Printf(\"error adding user %s to group %s: %s\", username, groupname, err)\n\t\tt.Fail()\n\t}\n\n\tok, err = lc.UserInGroup(username, groupname)\n\tif err != nil {\n\t\tlog.Printf(\"error checking for user %s in group %s: %s\", username, groupname, err)\n\t\tt.Fail()\n\t}\n\n\tassert.True(t, ok, \"test user successfully added to group\")\n\n\nRemove a user from a group:\n\n\tusername := \"fred\"\n\t\n\terr = lc.RemoveUserFromGroup(username, groupname)\n\tif err != nil {\n\t\tlog.Printf(\"error removing user %s to group %s: %s\", username, groupname, err)\n\t\tt.Fail()\n\t}\n\n\tok, err = lc.UserInGroup(username, groupname)\n\tif err != nil {\n\t\tlog.Printf(\"error checking for user %s in group %s: %s\", username, groupname, err)\n\t\tt.Fail()\n\t}\n\n\tassert.False(t, ok, \"test user successfully removed from group\")\n\t\nCreate a user (also created that user's group per posix standards):\n\n\tinfo := UserInfo{\n\t\tDN:        \"uid=mreynolds,ou=users,dc=scribd,dc=com\",\n\t\tUID:       \"mreynolds\",\n\t\tShell:     \"/bin/bash\",\n\t\tUidNumber: 1001,\n\t\tGidNumber: 1001,\n\t\tCN:        \"Malcom\",\n\t\tSN:        \"Reynolds\",\n\t\tHomeDir:   \"/home/mreynolds\",\n\t\tEmail:     \"mreynolds@scribd.com\",\n\t\tShadowLastChange: 10000,\n\t\tPubKey:    \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDN1812s1jlgPi4vchjNbg46oZ8smlxMwBY5j6V+phsnQyfk8bHhgWJ3MIUTNfx1OjJQreK7ct6kOJT2zhlb3AWVvZxFm/wbIZ8b91CMwacrjUvUU0zpQVqpbFrZoz0dJVXxb38jDsKwyQwxMW7tX4B14m9eFce+n48H/rDU4QDiyBvUzrWx+l9sZPn7UELhygwIp2O7xLxZHjigYnLzbK6bfwGBed3K7jg6FIjXPm2PzNf0pFrJqbSUgM9yJeUpXD83PiM1BkCRGAOaIRJxBS++UUDX46EbzMoBn/x6f/HDevjUTstcnJ4WVd8yeW2L+TzL/Wr5OvWp3OpWnCKvmx/10USW+PLbCvLB+iCyKzg2EMAsya31EvKAnlT0YGDvQozCer0lMuQTFdkPGB3FNRjv9WNvRFJmVH8jsOxFiNcC+UF/gOYa/CZxnn+5keZ99hSlop++f4rM3ncBG1r8C+bZ1cSZWgsNehkEV0JGQT3YsJT7ytX06l8QTVWRLv4CqlbFyirtL2mlnSq29u9eW8KEap3JVUuoLwx7yG5jcaxxrV1K4FyP1ENEm88fwgQxBxhGdvlVVPVhI/2TUgpO4GTSl98b1GAxwVOUyNpV9zU2SlfyYu6HL1oen4QpzDTIjS44NOzpSPUeSmgipPI1+gRbtGY8blTNnR8orr0SMJV6Q== mreynolds@test.com\",\n\t}\n\t\n\t// add user\n\terr = lc.AddUser(info)\n\tif err != nil {\n\t\tlog.Printf(\"Failed to add user %s to ldap: %s\", info.UID, err)\n\t\tt.Fail()\n\t}\n\n\t// verify user exists\n\tok, err := lc.UserExists(info.UID)\n\tif err != nil {\n\t\tlog.Printf(\"error searching for user %s in ldap: %s\", info.UID, err)\n\t\tt.Fail()\n\t}\n\n\tassert.True(t, ok, \"User successfully added to ldap\")\n\nDelete a user (also deletes the group):\n\n\t// remove user\n\terr = lc.RemoveUser(info.UID)\n\tif err != nil {\n\t\tlog.Printf(\"Error removing user %s from ldap: %s\", info.UID, err)\n\t\tt.Fail()\n\t}\n\n\t// verify user removed\n\tok, err = lc.UserExists(info.UID)\n\tif err != nil {\n\t\tlog.Printf(\"error searching for user %s in ldap: %s\", info.UID, err)\n\t\tt.Fail()\n\t}\n\n\tassert.False(t, ok, \"User successfully added to ldap\")\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscribd%2Fsimpleldapclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscribd%2Fsimpleldapclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscribd%2Fsimpleldapclient/lists"}