static bool wbinfo_lookupsid(const char *sid_str) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainSid sid; char *domain; char *name; enum wbcSidType type; /* Send off request */ wbc_status = wbcStringToSid(sid_str, &sid); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } wbc_status = wbcLookupSid(&sid, &domain, &name, &type); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } /* Display response */ d_printf("%s%c%s %d\n", domain, winbind_separator(), name, type); return true; }
static void print_sid(struct wbcDomainSid *sidptr, int raw) { int i; int num_auths; int num_auth = MAX_NUM_AUTHS; wbcErr rc; char *domain_name = NULL; char *sidname = NULL; enum wbcSidType sntype; if (raw) goto print_sid_raw; rc = wbcLookupSid(sidptr, &domain_name, &sidname, &sntype); if (!rc) { printf("%s", domain_name); if (strlen(domain_name)) printf("%c", '\\'); printf("%s", sidname); return; } print_sid_raw: num_auths = sidptr->num_auths; printf("S"); printf("-%d", sidptr->sid_rev_num); for (i = 0; i < num_auth; ++i) if (sidptr->id_auth[i]) printf("-%d", sidptr->id_auth[i]); for (i = 0; i < num_auths; i++) printf("-%u", le32toh(sidptr->sub_auths[i])); }
static bool test_wbc_users(struct torture_context *tctx) { const char *domain_name = NULL; uint32_t num_users; const char **users; int i; struct wbcInterfaceDetails *details; torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), "%s", "wbcInterfaceDetails failed"); domain_name = talloc_strdup(tctx, details->netbios_domain); wbcFreeMemory(details); torture_assert_wbc_ok(tctx, wbcListUsers(domain_name, &num_users, &users), "%s", "wbcListUsers failed"); torture_assert(tctx, !(num_users > 0 && !users), "wbcListUsers returned invalid results"); for (i=0; i < MIN(num_users,100); i++) { struct wbcDomainSid sid, *sids; enum wbcSidType name_type; char *domain; char *name; char *sid_string; uint32_t num_sids; torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, users[i], &sid, &name_type), "wbcLookupName of %s failed", users[i]); torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER, "wbcLookupName expected WBC_SID_NAME_USER"); wbcSidToString(&sid, &sid_string); torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type), "wbcLookupSid of %s failed", sid_string); torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER, "wbcLookupSid of expected WBC_SID_NAME_USER"); torture_assert(tctx, name, "wbcLookupSid returned no name"); wbcFreeMemory(domain); wbcFreeMemory(name); torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids), "wbcLookupUserSids of %s failed", sid_string); torture_assert_wbc_ok( tctx, wbcGetDisplayName(&sid, &domain, &name, &name_type), "wbcGetDisplayName of %s failed", sid_string); wbcFreeMemory(domain); wbcFreeMemory(name); wbcFreeMemory(sids); wbcFreeMemory(sid_string); } wbcFreeMemory(users); return true; }
wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid, char **pdomain, char **pfullname, enum wbcSidType *pname_type) { wbcErr wbc_status; char *domain = NULL; char *name = NULL; enum wbcSidType name_type; wbc_status = wbcLookupSid(sid, &domain, &name, &name_type); BAIL_ON_WBC_ERROR(wbc_status); if (name_type == WBC_SID_NAME_USER) { uid_t uid; struct passwd *pwd; wbc_status = wbcSidToUid(sid, &uid); BAIL_ON_WBC_ERROR(wbc_status); wbc_status = wbcGetpwuid(uid, &pwd); BAIL_ON_WBC_ERROR(wbc_status); wbcFreeMemory(name); name = wbcStrDup(pwd->pw_gecos); wbcFreeMemory(pwd); BAIL_ON_PTR_ERROR(name, wbc_status); } wbc_status = WBC_ERR_SUCCESS; done: if (WBC_ERROR_IS_OK(wbc_status)) { *pdomain = domain; *pfullname = name; *pname_type = name_type; } else { wbcFreeMemory(domain); wbcFreeMemory(name); } return wbc_status; }
bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, const char **domain, const char **name, enum lsa_SidType *name_type) { struct wbcDomainSid dom_sid; wbcErr result; enum wbcSidType type; char *domain_name = NULL; char *account_name = NULL; memcpy(&dom_sid, sid, sizeof(dom_sid)); result = wbcLookupSid(&dom_sid, &domain_name, &account_name, &type); if (result != WBC_ERR_SUCCESS) return false; /* Copy out result */ if (domain) { *domain = talloc_strdup(mem_ctx, domain_name); } if (name) { *name = talloc_strdup(mem_ctx, account_name); } *name_type = (enum lsa_SidType)type; DEBUG(10, ("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n", sid_string_dbg(sid), domain_name, account_name)); wbcFreeMemory(domain_name); wbcFreeMemory(account_name); if ((domain && !*domain) || (name && !*name)) { DEBUG(0,("winbind_lookup_sid: talloc() failed!\n")); return false; } return true; }
static bool test_wbc_groups(struct torture_context *tctx) { const char *domain_name = NULL; uint32_t num_groups; const char **groups; int i; struct wbcInterfaceDetails *details; torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), "%s", "wbcInterfaceDetails failed"); domain_name = talloc_strdup(tctx, details->netbios_domain); wbcFreeMemory(details); torture_assert_wbc_ok(tctx, wbcListGroups(domain_name, &num_groups, &groups), "wbcListGroups in %s failed", domain_name); torture_assert(tctx, !(num_groups > 0 && !groups), "wbcListGroups returned invalid results"); for (i=0; i < MIN(num_groups,100); i++) { struct wbcDomainSid sid; enum wbcSidType name_type; char *domain; char *name; char *sid_string; torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, groups[i], &sid, &name_type), "wbcLookupName for %s failed", domain_name); wbcSidToString(&sid, &sid_string); torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type), "wbcLookupSid of %s failed", sid_string); wbcFreeMemory(sid_string); torture_assert(tctx, name, "wbcLookupSid returned no name"); } wbcFreeMemory(groups); return true; }
wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid, int num_rids, uint32_t *rids, const char **pp_domain_name, const char ***pnames, enum wbcSidType **ptypes) { struct wbcDomainSid obj_sid = {0}; size_t c; wbcErr err; char *domain; char *name; enum wbcSidType type; const char **names = NULL; enum wbcSidType *types = NULL; obj_sid.sid_rev_num = dom_sid->sid_rev_num; obj_sid.num_auths = dom_sid->num_auths + 1; for (c = 0; c < 6; c++) { obj_sid.id_auth[c] = dom_sid->id_auth[c]; } for (c = 0; c < WBC_MAXSUBAUTHS; c++) { obj_sid.sub_auths[c] = dom_sid->sub_auths[c]; } names = wbcAllocateStringArray(num_rids + 1); if (names == NULL) { err = WBC_ERR_NO_MEMORY; goto done; } types = wbcAllocateMemory(num_rids + 1, sizeof(enum wbcSidType), NULL); if (types == NULL) { err = WBC_ERR_NO_MEMORY; goto done; } for (c = 0; c < num_rids; c++) { obj_sid.sub_auths[obj_sid.num_auths - 1] = rids[c]; err = wbcLookupSid(&obj_sid, &domain, &name, &type); if (err != WBC_ERR_SUCCESS) { goto done; } names[c] = strdup(name); wbcFreeMemory(name); if (names[c] == NULL) { err = WBC_ERR_NO_MEMORY; goto done; } types[c] = type; if (c == 0) { *pp_domain_name = domain; } else { wbcFreeMemory(domain); } } *pnames = names; *ptypes = types; err = WBC_ERR_SUCCESS; done: if (err != WBC_ERR_SUCCESS) { wbcFreeMemory(types); wbcFreeMemory(names); } return err; }
int cifs_idmap_sid_to_str(void *handle __attribute__ ((unused)), const struct cifs_sid *csid, char **string) { int rc; wbcErr wbcrc; char *domain = NULL; char *name = NULL; enum wbcSidType sntype; struct wbcDomainSid wsid; size_t len; csid_to_wsid(&wsid, csid); wbcrc = wbcLookupSid(&wsid, &domain, &name, &sntype); if (!WBC_ERROR_IS_OK(wbcrc)) { *plugin_errmsg = wbcErrorString(wbcrc); return -EIO; } /* +1 for '\\' and +1 for NULL terminator */ len = strlen(domain) + 1 + strlen(name) + 1; *string = malloc(len); if (!*string) { *plugin_errmsg = "Unable to allocate memory"; rc = -ENOMEM; goto out; }